mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-22 12:09:34 +08:00

* 添加适用于DataSet和DateTime的JSON自定义转换器。 * 添加JsonManager,删除JsonObject并仅使用SocketObject * 移除Newtonsoft.Json引用
32 lines
1013 B
C#
32 lines
1013 B
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using Milimoe.FunGame.Core.Library.Constant;
|
|
|
|
namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
|
|
{
|
|
public class DateTimeConverter : JsonConverter<DateTime>
|
|
{
|
|
public override DateTime Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options)
|
|
{
|
|
if (reader.TokenType != JsonTokenType.String)
|
|
{
|
|
throw new JsonException();
|
|
}
|
|
|
|
string date = reader.GetString() ?? "";
|
|
|
|
if (DateTime.TryParseExact(date, General.GeneralDateTimeFormat, null, System.Globalization.DateTimeStyles.None, out DateTime result))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
throw new JsonException();
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
|
{
|
|
writer.WriteStringValue(value.ToString(General.GeneralDateTimeFormat));
|
|
}
|
|
}
|
|
}
|