初步完成代码级重写通用接口功能
This commit is contained in:
@@ -47,4 +47,8 @@ public class DObject : Dictionary<string, object>
|
||||
}
|
||||
}
|
||||
|
||||
public static DObject? FromObject(object? data)
|
||||
{
|
||||
return data?.Adapt<DObject>(AdapterCfg.ExactCase);
|
||||
}
|
||||
}
|
||||
|
||||
31
common/Tnb.Common/Utils/AdapterCfg.cs
Normal file
31
common/Tnb.Common/Utils/AdapterCfg.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Mapster;
|
||||
|
||||
public class AdapterCfg
|
||||
{
|
||||
public static TypeAdapterConfig IgnoreNull { get; internal set; }
|
||||
public static TypeAdapterConfig ExactCase { get; internal set; }
|
||||
|
||||
static AdapterCfg()
|
||||
{
|
||||
IgnoreNull = TypeAdapterConfig.GlobalSettings.Clone();
|
||||
IgnoreNull.Default.IgnoreNullValues(true);
|
||||
|
||||
ExactCase = TypeAdapterConfig.GlobalSettings.Clone();
|
||||
ExactCase.Default.NameMatchingStrategy(NameMatchingStrategy.Exact);
|
||||
}
|
||||
|
||||
public static void ConfigGlobal()
|
||||
{
|
||||
TypeAdapterConfig.GlobalSettings.Default.PreserveReference(true);
|
||||
TypeAdapterConfig.GlobalSettings.NewConfig<JToken, JToken>().MapWith(json => json);
|
||||
TypeAdapterConfig.GlobalSettings.NewConfig<JObject, JObject>().MapWith(json => json);
|
||||
TypeAdapterConfig.GlobalSettings.NewConfig<JArray, JArray>().MapWith(json => json);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user