Clone Whole Object Graph

后端 未结 4 1709
心在旅途
心在旅途 2020-12-29 00:15

While using this code to serialize an object:

public object Clone()
{
    var serializer = new DataContractSerializer(GetType());
    using (var ms = new Sys         


        
4条回答
  •  时光说笑
    2020-12-29 00:37

    Either annotate your classes with [DataContract] or add your child types in the constructor of DatacontractSerializer.

    var knownTypes = new List {typeof(Class1), typeof(Class2), ..etc..};
    var serializer = new DataContractSerializer(GetType(), knownTypes);
    

提交回复
热议问题