对象的深拷贝

 class SerializeTool
    {
        public static object DeepClone(object original)
        {
            //释放流对象
            using (Stream stream = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();

                formatter.Serialize(stream, formatter);

                //反序列化之前,定位到内存流的起始位置
                stream.Position = 0;

                return formatter.Deserialize(stream);
            }
        }


    }

 

posted @ 2012-12-05 08:53  viola  阅读(220)  评论(0编辑  收藏  举报