C# 原型模式(Prototype)
参考地址:https://www.cnblogs.com/ckka/p/11368572.html
/// <summary> /// 信息 /// </summary> public class DataInfo { public long Id { get; set; } public string Name { get; set; } public DataInfo Clone() { return (DataInfo)this.MemberwiseClone(); } /// <summary> /// 深拷贝 /// </summary> /// <returns>返回一个全新的Person对象</returns> public DataInfo DeepClone() { //创建一个内存流 using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { //创建一个二进制序列化对象 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); //将当前对象序列化写入ms内存流中 bf.Serialize(ms, this); //设置流读取的位置 ms.Position = 0; //将流反序列化为Object对象 return bf.Deserialize(ms) as DataInfo; } } }