/// <summary> /// 对象深度Copy /// </summary> /// <typeparam name="T"></typeparam> /// <param name="obj"></param> /// <returns></returns> public static T DeepCopy<T>(T obj) { if (Object.ReferenceEquals(obj, null)) { return default(T); } string s = JsonConvert.SerializeObject(obj); return JsonConvert.DeserializeObject<T>(s); } /// <summary> /// 对象深度Copy /// </summary> /// <typeparam name="T"></typeparam> /// <param name="obj"></param> /// <returns></returns> public static Tout DeepCopy<Tin, Tout>(Tin obj) { if (Object.ReferenceEquals(obj, null)) { return default(Tout); } string s = JsonConvert.SerializeObject(obj); return JsonConvert.DeserializeObject<Tout>(s); }
标签:Copy,return,C#,JsonConvert,default,复制,obj,序列化 From: https://www.cnblogs.com/hofmann/p/17565931.html