Skip to content

Gendarme.Rules.Serialization.MarkAllNonSerializableFieldsRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

MarkAllNonSerializableFieldsRule

Assembly: Gendarme.Rules.Serialization
Version: git

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

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally