I really like the ease and flexibility of using XmlSerializer
to persist configuration data for my application. However, I can see potential maintainability issues.
From looking at my class definitions, it is not obvious that the reason certain fields are exposed as properties is for serialization purposes. Somebody could come along and remove a property (leaving the private field alone) and inadvertently cause issues due to important information no longer being serialized to XML.
I could add comments to explain this, but I'd rather the code spoke for itself.
There exists the [Serializable]
attribute (which hints that the class is to be serialized), but this isn't actually required for the XmlSerializer
and is therefore unnecessary.
I could write some custom serialization code but then I lose the simplicity of using XmlSerializer
.
Is there a way of decorating my code to make it clear which classes and which properties are candidates for XML serialization?