Skip to content

Gendarme.Rules.Design.FlagsShouldNotDefineAZeroValueRule(git)

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

FlagsShouldNotDefineAZeroValueRule

Assembly: Gendarme.Rules.Design
Version: git

Description

This rule ensures that enumerations decorated with the [System.Flags] attribute do not contain a 0 value. This value would not be usable with bitwise operators.

Examples

Bad example (using 0 for a normal value):

[Flags]
[Serializable]
enum Access {
    Read = 0,
    Write = 1
}

Bad example (using None):

[Flags]
[Serializable]
enum Access {
    // this is less severe since the name of the 0 value helps
    None = 0,
    Read = 1,
    Write = 2
}

Good example:

[Flags]
[Serializable]
enum Access {
    Read = 1,
    Write = 2
}

Source code

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

Clone this wiki locally