精选代码备份
1
public
class ObjectUtils
2 {
3 public T Clone<T>( object instance)
4 {
5 BinaryFormatter formatter = new BinaryFormatter();
6 MemoryStream stream = new MemoryStream();
7 formatter.Serialize(stream, instance);
8 stream.Seek( 0, SeekOrigin.Begin);
9 T newObject = (T)formatter.Deserialize(stream);
10 return newObject;
11 }
12 }
2 {
3 public T Clone<T>( object instance)
4 {
5 BinaryFormatter formatter = new BinaryFormatter();
6 MemoryStream stream = new MemoryStream();
7 formatter.Serialize(stream, instance);
8 stream.Seek( 0, SeekOrigin.Begin);
9 T newObject = (T)formatter.Deserialize(stream);
10 return newObject;
11 }
12 }