How can I serialize an object with a Dictionary property?

前端 未结 7 599
故里飘歌
故里飘歌 2021-01-04 08:04

In the example code below, I get this error:

Element TestSerializeDictionary123.Customer.CustomProperties vom Typ System.Collec

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-04 08:52

    I've just found this blog post by Rakesh Rajan which describes one possible solution:

    Override XmlSerialization by making the type implement the System.Xml.Serialization.IXmlSerializable class. Define how you want the object to be serialized in XML in the WriteXml method, and define how you could recreate the object from an xml string in the ReadXml method.

    But this wouldn't work as your Dictionary contains an object rather than a specific type.

提交回复
热议问题