I want to be able to determine if an enum value belongs to a certain group. See the pseudo example:
[Flags]
public enum Animals
{
Dog = 1,
Cat = 2,
WildAnimal = Dog | Cat,
Fly = 4,
Bee = 8,
Insect = Fly | Bee
}
public static bool IsInsect(Animals animals)
{
return Animals.Insect.Qualifies(animals);
}
public static bool Qualifies(this Animals groupName, Animals value)
{
//Is there a bitwise operation for it?
}
Use HasFlag
method on enum.
http://msdn.microsoft.com/en-us/library/system.enum.hasflag.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With