Let's say I need an enumeration both in flags and in an option other than flags.
Option 1: I could duplicate everything:
enum Color { Red, Blue, Green } [Flags] enum Colors { None = 0, Red = 1, Blue = 2, Green = 4 }
Option 2: I could just use the Flags option for everything:
Colors currentColor; // ugly, since neither "None" nor "Red | Blue" should be valid
I do not like any of them: in Option 1, Color.Red and Colors.Red are not completely connected, which may require code binding. In addition, I would have to synchronize the two rewrites. The disadvantage of option 2 is obvious. What I really like is something like
enum Colors = Flag set of Color;
Is there a more elgant solution to this requirement?
source share