How can I group Enum values?
Assume I have an enum like
public enum Colors
{
LightBlue,
LightGreen,
DarkGreen,
Black,
White,
LightGry,
Yellow
}
Now I want to define some groups of colors, e.g. the light colors (LightBlue, LightGreen, White, LightGray, Yellow) and dark colors (Black, DarkGreen).
So I can ask for groups at different places in my code.
If I remember correctly my Java time I just could add methods to the enums in Java. I think that is not possible in C#. But maybe there are other ways.
Edit1: Of course I can add a Utility class with static member like IsADarkColor(Colors c). But I would like do it without an additional class because I could forget that related class when I need that feature.
This is when Extension Methods come in handy:
As long as these two classes are in the same namespace, you can see the static method as if it belonged to the Color class:
(hat tip to @Abdul for making me think of extension methods)