How to serialize/deserialize simple classes to XML and back

前端 未结 4 881
Happy的楠姐
Happy的楠姐 2020-11-28 10:22

Sometimes I want to emulate stored data of my classes without setting up a round trip to the database. For example, let\'s say I have the following classes:



        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 11:01

    Just mark up what you want to serialize with [XmlElement(name)] (or XmlAttribute, XmlRoot, etc) and then use the XmlSerializer. If you need really custom formating, implement IXmlSerializable.

提交回复
热议问题