Why XML-Serializable class need a parameterless constructor

后端 未结 4 1670
盖世英雄少女心
盖世英雄少女心 2020-11-22 05:11

I\'m writing code to do Xml serialization. With below function.

public static string SerializeToXml(object obj)
{
    XmlSerializer serializer = new XmlSeria         


        
4条回答
  •  广开言路
    2020-11-22 05:32

    During an object's de-serialization, the class responsible for de-serializing an object creates an instance of the serialized class and then proceeds to populate the serialized fields and properties only after acquiring an instance to populate.

    You can make your constructor private or internal if you want, just so long as it's parameterless.

提交回复
热议问题