My application contains a set of model classes. e.g. Person, Department…
The user changes values for instances of these classes in the UI and the classes are persisted to my “project” file. Next time the user can open and edit the project.
Next version of my product may change the model classes drastically. It will still need to open existing projects files (I will know how to handle missing data).
How is it best to persist my model classes to the project file?
The easiest way to persist classes is Data contract serialization. However it will fail on breaking changes (I expect to have such). How to handle this?
- use some other persistence, e.g. name-value collection or db which is more tolerance
- ship a “project converter” application to migrate old projects. This requires to either ship with both old and new models or to manipulate xml, which is best?
I would recommend including a version number in your project file schema. Then provide XSLT to convert between different versions of the project schema. When a file is opened, first open as XML and check the version. If it’s not the latest version, up-convert it, then process as normal.