Object deep copy in Silverlight

て烟熏妆下的殇ゞ 提交于 2019-12-02 00:26:08

Implement the DataContractSerializer attributes (DataContract, DataMember) on your classes and call DatacontractSerializer to serialize it to a MemoryStream, then use it again to serialize out of the MemoryStream to a new instance of the object. By far the easiest to understand, and quite performant too.

Example of class definition :

[DataContract]
class MyClass
{
    [DataMember]
    public int MyValue {get;set;}
    [DataMember]
    public string MyOtherValue {get;set;}
}

The method of cloning from one class instance to another is covered in the Microsoft documentation http://msdn.microsoft.com/en-us/library/ms752244(v=vs.110).aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!