using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace Extend
{
//
// 摘要:
// 深拷贝类
public static class Clone
{
// Deep clone
public static T DeepClone<T>(this T obj)
{
using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, obj);
ms.Position = 0;
return (T)formatter.Deserialize(ms);
}
}
}
}
参考:https://stackoverflow.com/questions/129389/how-do-you-do-a-deep-copy-of-an-object-in-net