Skip to content

Gendarme.Rules.Serialization.UseCorrectSignatureForSerializationMethodsRule(2.10)

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

UseCorrectSignatureForSerializationMethodsRule

Assembly: Gendarme.Rules.Serialization
Version: 2.10

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
Clone this wiki locally