Using XmlSerializer with private and public const properties

前端 未结 6 2066
渐次进展
渐次进展 2020-12-19 08:07

What\'s the simplest way to get XmlSerializer to also serialize private and \"public const\" properties of a class or struct? Right not all it will output for me is things

6条回答
  •  眼角桃花
    2020-12-19 09:00

    Check out DataContractSerializer, introduced in .NET 3.0. It also uses XML format, and in many ways, it is better than XmlSerializer, including dealing with private data. See http://www.danrigsby.com/blog/index.php/2008/03/07/xmlserializer-vs-datacontractserializer-serialization-in-wcf/ for a full comparison.

    If you only have .NET 2.0, there's the BinarySerializer that can deal with private data, but of course it's a binary format.

提交回复
热议问题