views:

135

answers:

1

On my current project, I am using FxCop to work through various code analysis warnings. For the Naming Rules, I have the option to either change names to match the rules or make the decision to keep my current spelling and suppress the warning. In regards to classes or attributes that are marked as [Serializable], I'm interested in the ramifications of name changes. Particularly, how would backwards compatibility with existing serialized data be affected?

+2  A: 

If you change the field names and need to read old data serialized before your changes, then it could get messy. BinaryFormatter is largely a field(name)-based serializer, and it won't be happy. Changing properties and methods should be fine as long as no external code is referencing it (and be sure to run your unit tests). Viable options at that point: manual serialization (ISerializable) and serialization surrogates. Lots of pain.

If you are using XmlSerializer / DataContractSerialializer then you can name the serialization name separately to the member name, so really easy to fix. And some other serializers don't use names at all ;-p

XmlSerializer example:

[XmlElement("Color")] // original spelling
public string Colour {get;set;} // now with the correct spelling ;-p
Marc Gravell