Will modifying shared methods change the class that reference them?
I'm wondering what will actually change a class, in the sense that serialized objects of this class will no longer be recognized.
If the class has reference to shared methods of another class. Will changing such shared methods also change the classes that reference them?
And what about changing extension methods to custom classes, will开发者_运维知识库 that impact the class "signature", if that's an appropriate term?
A good reference for this is Version Tolerant Serialization on MSDN. In short, changes to Shared (static in C#) methods do not affect the deserialization of an object:
Never remove a serialized field.
Never apply the NonSerializedAttribute attribute to a field if the attribute was not applied to the field in the previous version.
Never change the name or the type of a serialized field.
When adding a new serialized field, apply the OptionalFieldAttribute attribute.
When removing a NonSerializedAttribute attribute from a field (that was not serializable in a previous version), apply the OptionalFieldAttribute attribute.
For all optional fields, set meaningful defaults using the serialization callbacks unless 0 or nullas defaults are acceptable.
As a minor aside: changes to certain special methods related to serialization could affect deserialization. But you'd be making a conscious decision to change those.
Serialized objects change when the data changes. References to methods are never serialized; they are part of the code rather than the data.
If you're doing binary serialization, changing both private and public properties of the class that gets serialized will "break the interface". If you're doing XML or JSON, changing of public properties will alter how its serialized. Methods do not get serialized, so you can change those and it will still work (so long as you don't change the signature).
精彩评论