It's possible to bitwise or enums. Typically this is done on Flags enums.
Eg var foo = MyEnum.ABC | MyEnum.XCN
I have tried to create a method convert an array of enums into a combined enum using generics.
Here is what I have tried:
private T CombineFlags<T>(params T[] flags) where T : struct, IConvertible
{
return flags.Select(flag => flag).Aggregate((x, y) => x | y);
}
However, I can't apply operator '\' to T and T. Casting doesn't seem to help. struct, IConvertible
seem to be the closest I can get to enums, but obviously not close enough to use the '|' operator. System.Enum also isn't very helpful.
How can I perform this operation on the generic enum? (Is it possible?)