深度复制
public static T Clone<T>(T RealObject) { using (Stream stream = new MemoryStream()) { XmlSerializer serializer = new XmlSerializer(typeof(T)); serializer.Serialize(stream, RealObject); stream.Seek(0, SeekOrigin.Begin); return (T)serializer.Deserialize(stream); } }
c#框架中提供的copy基本都是浅复制,这样序列化可以做到深复制。