/// <summary>
/// 深度复制
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="SourceObj"></param>
/// <returns></returns>
public static T DeepClone<T>(this T SourceObj) where T : new()
{
string rtnStr = JsonConvert.SerializeObject(SourceObj);
object obj = JsonConvert.DeserializeObject(rtnStr, typeof(T));
T DestObj = default(T);
if (obj != null && obj is T)
{
DestObj = (T)obj;
}
return DestObj;
}
时间: 2024-10-13 22:31:47