Skip to content

Gendarme.Rules.Serialization.UseCorrectSignatureForSerializationMethodsRule(git)

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

UseCorrectSignatureForSerializationMethodsRule

Assembly: Gendarme.Rules.Serialization
Version: git

Description

This rule checks for methods which use the serialization attributes: OnSerializing, OnDeserializing, OnSerialized, OnDeserialized. You must ensure that these methods have the correct signature. They should be private, return void and have a single parameter of type StreamingContext. Failure to have the right signature can, in some circumstances, make your assembly unusable at runtime.

Examples

Bad example:

[Serializable]
public class Bad {
    [OnSerializing]
    public bool Serializing (StreamingContext context)
    {
    }
}

Good example:

[Serializable]
public class BadClass {
    [OnSerializing]
    private void Serializing (StreamingContext context)
    {
    }
}

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