XmlSerializer equivalent of IExtensibleDataObject
- by demoncodemonkey
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?