The MSDN documentation for the Flag
attribute says that you should:
Define enumeration constants in powers of two, that is, 1, 2, 4, 8, and so on. This means the individual flags in combined enumeration constants do not overlap.
...and of course I always try to remember to do that. However, nothing enforce that and if you just create an enumeration the 'basic' way like...
[Flags]
public enum BrokenEnum
{
None,
FirstOption,
SecondOption,
ThirdOption
}
...it won't behave as expected. To combat this, I'm looking for some kind of static code analysis (like FxCop) that can warn me when an enum like the one above exists in my code. The closest such warning I could find was 'CA1008: Enums should have zero value' - which is also helpful for designing flags enumeration correctly but isn't enough.
What is the best way to find incorrectly designed flags enums in my code? The more automated the solution, the better.