C# 动态对象转换为实体对象支持泛型(DynamicToEntity)
C# 动态对象转换为实体对象支持泛型(DynamicToEntity)
C# Code:
/// <summary>
/// 动态对象转换为实体对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="o"></param>
/// <returns></returns>
public static T DynamicToEntity<T>(dynamic o)
{
string json = JsonConvert.SerializeObject(o, JsonTool.Settings);
return JsonConvert.DeserializeObject<T>(json, JsonTool.Settings);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// 动态对象转换为实体对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="o"></param>
/// <returns></returns>
public static T DynamicToEntity<T>(dynamic o)
{
string json = JsonConvert.SerializeObject(o, JsonTool.Settings);
return JsonConvert.DeserializeObject<T>(json, JsonTool.Settings);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
C# Code:
/// <summary>
/// Json设置
/// </summary>
public static JsonSerializerSettings Settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DateFormatString = "yyyy-MM-dd HH:mm",
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// Json设置
/// </summary>
public static JsonSerializerSettings Settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DateFormatString = "yyyy-MM-dd HH:mm",
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
//来源:C/S框架网 | www.csframework.com | QQ:23404761
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网