The Problem
I'm developing a game and using the XmlSerializer to store some user data.
While it isn't an immediate problem, I'm trying to conceptualize what would happen if I needed to update Save Data to a newer version of my game. Since the XmlSerializer reads as a Type, if I update my class with more variables, the save file becomes unreadable.
After doing some research, I discovered the XmlDocument class, which is able to read XML files as that type. This allows the data stored to be arbitrary, allowing me to read and write data accordingly.
What's confusing me is how exactly I would go about this. Is there an easy way to populate an XmlDocument with the Nodes/Elements of a custom class? And how can I detect when data is missing and needs to be added to the XML file?
Example
If you were confused by the question, here's a simple example of what I would like to accomplish:
<FileData version="Original File">
<foo>14</foo>
</FileData>
Several versions later, I update my class to look like this:
class FileData {
var foo = 14;
var bar = 4;
}
Now I need the XML file to look like this before I can use XmlSerializer:
<FileData version="Updated File">
<foo>14</foo>
<bar>4</bar>
</FileData>