Object deep copy in Silverlight

后端 未结 1 1205
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 16:43

I was trying to create copy of objects in silverligth 5 where interfaces like IFormatters and IcCloanble do not support. *

My objects are like this: (No

相关标签:
1条回答
  • 2021-01-21 17:27

    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

    0 讨论(0)
提交回复
热议问题