Friday, March 14, 2008

Gotcha: Hidden [Flags] attribute on bitfield enumerations

 

Just got reminded of a still unfixed bug.

Consider an enumeration of the following kind:

    /// <summary>
/// Modes enumeration
/// </summary>
[Flags]
public enum Modes {
/// <summary>
/// Yes
/// </summary>
Foo = 1,
/// <summary>
/// No
/// </summary>
Bar = 2,
/// <summary>
/// Maybe
/// </summary>
Both = Foo|Bar
}

For the user of this enumeration, it is essential to know that it in fact is a bitfield (as specified by the FlagsAttribute).


However, both Intellisense and object browser fails to give any hint about this fact!?! (Yes, this occurs in both VS 2005 and VS 2008)


So for now, remember to document (within in the summary, so it is visible) this fact for your fellow developers.


No comments: