For my game save/load I use the BinaryFormatter.Serialize() and Deserialize() to read/write a class containing my save data. All members of the class are initialised in the constructor to sensible initial values.
However, a problem occurs when adding new data like so:
Add a new member to the save data class
Run the game
Save data is initialised, new item is initialised to a sensible value.
Load previous save data with BinaryFormatter.Deserialize()
New item is now null/zero
My question is simply how best to handle this case, as after the load, some items will need to be re-initialised and managing this over the course of many version of the save data may become a real pain.
Is there a way to deserialize without nulling missing items? Or a clever way to re-initialise anything that was nulled during the load?
Implement the ISerializable interface, it allows you to write a custom serialization and deserialization procedure for a class. Also take a look at Data Contract Versioning.