Deep Clone
2009-10-13 20:02
155 查看
Have you ever used the Clone() method of DataSet? This method creates an empty class with same structure as original DataSet.
You can write your own clonable classes. To do so, you must implement IClonable. The following code shows a clonable Test class.
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public Class Test : IClonable
{
public Test()
{
}
// deep copy in separeate memory space
public object Clone()
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, this);
ms.Position = 0;
object obj = bf.Deserialize(ms);
ms.Close();
return obj;
}
}
You can write your own clonable classes. To do so, you must implement IClonable. The following code shows a clonable Test class.
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public Class Test : IClonable
{
public Test()
{
}
// deep copy in separeate memory space
public object Clone()
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, this);
ms.Position = 0;
object obj = bf.Deserialize(ms);
ms.Close();
return obj;
}
}
相关文章推荐
- javascript深拷贝(deepClone)详解
- Prototype中的shallow clone 与deep clone 与new 一个实例的区别
- 深拷贝(deep clone)与浅拷贝(shallow clone)
- Cloneable --shadow clone --deep clone
- Java Clone, Shallow Copy and Deep Copy
- DeepClone与ShadowClone(downmoon)
- java实现shadow clone(浅克隆)与深克隆(deep clone)
- java实现深克隆(deep clone)
- ASP.NET下Control的Deep Clone
- 实现对象深度克隆(deepClone)的三种方案
- java shallow clone(浅克隆)与深克隆(deep clone) 笔记
- 深拷贝(deep clone)和浅拷贝(shallow copy)
- 【学习笔记一】- JS 类型识别 和 deepclone 深复制
- JavaScript深度复制(deep clone)的实现方法
- DeepClone与ShadowClone
- Deep Clone Object
- java deep copy&clone
- 数组克隆及对象的深、浅克隆(deep clone、shallow clone)
- Deep clone object by serialization