Skip to content

Gendarme.Rules.Serialization.MarkAllNonSerializableFieldsRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

MarkAllNonSerializableFieldsRule

Assembly: Gendarme.Rules.Serialization
Version: 2.10

Description

This rule checks for serializable types, i.e. decorated with the Serializable attribute, and checks to see if all its fields are serializable as well. If not the rule will fire unless the field is decorated with the NonSerialized attribute. The rule will also warn if the field type is an interface as it is not possible, before execution time, to know for certain if the type can be serialized or not.

Examples

Bad example:

class NonSerializableClass {
}
[Serializable]
class SerializableClass {
    NonSerializableClass field;
}

Good example:

class NonSerializableClass {
}
[Serializable]
class SerializableClass {
    [NonSerialized]
    NonSerializableClass field;
}

Notes

  • This rule is available since Gendarme 2.0
Clone this wiki locally