开发者

XmlSerializer equivalent of IExtensibleDataObject

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 cont开发者_如何学编程rol 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?


[XmlAnyAttribute] and [XmlAnyElement].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜