C# 动态对象转换为实体对象支持泛型(DynamicToEntity)
作者:C/S框架网|www.cscode.ne  发布日期:2021-03-18 12:21:40
  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



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



上一篇 下一篇