XmlSerializer equivalent of IExtensibleDataObject

做~自己de王妃 提交于 2019-12-02 05:36:25

问题


With DataContracts you can derive from IExtensibleDataObject to allow round-tripping to work without losing any unknown additional data from your XML file.

I can't use DataContract because I need to control the formatting of the output XML. But I also need to be able to read a future version of the XML file in the old version of the app, without losing any of the data from the XML file.

e.g.

XML v1:

<Person>
    <Name>Fred</Name>
</Person>

XML v2:

<Person>
    <Name>Fred</Name>
    <Age>42</Age>
</Person>

If reading an XML v2 file from v1 of my app, deserializing and serializing it again turns it into an XML v1 file. i.e. the "Age" field is erased.

Is there anything similar to IExtensibleDataObject that I can use with XmlSerializer to avoid the Age field disappearing?


回答1:


[XmlAnyAttribute] and [XmlAnyElement].



来源:https://stackoverflow.com/questions/2511298/xmlserializer-equivalent-of-iextensibledataobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!