Uses serialization to make a deep copy
来源:互联网 发布:tvb直播软件 编辑:程序博客网 时间:2024/05/21 01:48
private static Object DeepClone(Object original)
{
// Construct a temporary memory stream
using (MemoryStream stream = new MemoryStream())
{
// Construct a serialization formatter that does all the hard work
BinaryFormatter formatter = new BinaryFormatter();
// This line is explained in this chapter's "Streaming Contexts" section
formatter.Context = new StreamingContext(StreamingContextStates.Clone);
// Serialize the object graph into the memory stream
formatter.Serialize(stream, original);
// Seek back to the start of the memory stream before deserializing
stream.Position = 0;
// Deserialize the graph into a new set of objects and
// return the root of the graph (deep copy) to the caller
return formatter.Deserialize(stream);
}
}
{
// Construct a temporary memory stream
using (MemoryStream stream = new MemoryStream())
{
// Construct a serialization formatter that does all the hard work
BinaryFormatter formatter = new BinaryFormatter();
// This line is explained in this chapter's "Streaming Contexts" section
formatter.Context = new StreamingContext(StreamingContextStates.Clone);
// Serialize the object graph into the memory stream
formatter.Serialize(stream, original);
// Seek back to the start of the memory stream before deserializing
stream.Position = 0;
// Deserialize the graph into a new set of objects and
// return the root of the graph (deep copy) to the caller
return formatter.Deserialize(stream);
}
}
- Uses serialization to make a deep copy
- A practical guide to C++ serialization
- make a copy of list in python
- A Guide to Deep Learning
- A Trip To Deep Learning
- deep copy
- how to copy a linkedlist
- How to Copy a Website
- How To Make A Keygen
- How to make a patch
- how-to-make-a-rpg
- How to make a ipcamera
- memory map program --------uses mmap function to copy file fd to stdout
- Deep copy & Shallow copy
- Shallow copy & Deep copy
- Deep Copy in C# (Cloning for a user defined class)
- make and build package, copy files to dest dir
- Deep clone object by serialization
- 第八周4
- 与python的初次接触
- 二叉排序树
- Understanding ELF using readelf and objdump
- 怎样减少新终端开发的问题数
- Uses serialization to make a deep copy
- 10.24
- 10.26
- MYSQL命令大全
- Flex 4中的 CSS
- Asset Store 资源商店
- 数据结构复习之【队列】
- 10.28
- Tomcat登陆用户名,密码不能进入