Once learning a little about xml serialization and actually starting to take advantage of it in real world scenarios, I'm working on putting together a short article on the how to use serialization, what I've found to be useful and, of course, what I've found to be annoyances and limitations (usually both at the same time ;-) ).
A rough outline of some of the topics I'll be touching upon:
- Briefly show how to use the <Serialization()> attribute to “automatically“ serialize/deserialize a class to/from a file.
- Since I'm not a fan of how that file ends up looking, I'll be going into some detail on how to control how the xml is structured.
- Show some examples of using different data types (base types, enums) and data structures (flat, collections, arrays) being serialized.
- Along the way, discuss some of the pitfalls that I've run into so that you can avoid them.
Using these methods, it's pretty simple to serialize/deserialize your classes to/from xml; more importantly, it's easy to extend the classes and the resulting changes to the xml is pretty much automatic; thus saving you a lot of development time versus either reading/writing the xml manually using the xmlreader/xmlwriter or resorting to writing your own custom formatting code (ini, registry, etc.).