使用序列化进行Clone

    public class ObjectUtils
    {
        public T Clone<T>(object instance)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();
            formatter.Serialize(stream, instance);
            stream.Seek(0, SeekOrigin.Begin);
            T newObject = (T)formatter.Deserialize(stream);
            return newObject;
        }
    }
阅读更多
文章标签: stream object class
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭