mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-22 03:59:35 +08:00

* 更换任务计划实现方式;修改自定义 Json 转换器基类 * RunTimeController 添加 HTTPClient(WebSocket)支持;SQL 查询修改为参数化,防止注入
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using Milimoe.FunGame.Core.Interface.Base;
|
|
|
|
namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
|
{
|
|
public abstract class BaseEntityConverter<T> : JsonConverter<T>, IEntityConverter<T>
|
|
{
|
|
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
T? result = default;
|
|
Dictionary<string, object> convertingContext = [];
|
|
|
|
while (reader.Read())
|
|
{
|
|
if (reader.TokenType == JsonTokenType.EndObject) break;
|
|
|
|
if (reader.TokenType == JsonTokenType.PropertyName)
|
|
{
|
|
result ??= NewInstance();
|
|
string propertyName = reader.GetString() ?? "";
|
|
reader.Read();
|
|
ReadPropertyName(ref reader, propertyName, options, ref result, convertingContext);
|
|
}
|
|
}
|
|
|
|
if (result != null)
|
|
{
|
|
AfterConvert(ref result, convertingContext);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public abstract T NewInstance();
|
|
|
|
public abstract void ReadPropertyName(ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref T result, Dictionary<string, object> convertingContext);
|
|
|
|
public virtual void AfterConvert(ref T result, Dictionary<string, object> convertingContext)
|
|
{
|
|
// do nothing
|
|
}
|
|
}
|
|
}
|