A frustration about the Generics framework in .NET is that it's not possible to specify a generic constraint to be any enumeration.
1: public class SomeClassName<T> where : Enum
2: {
3: // ...
4: }
A workaround I use to enforce the constraint, although not pretty is below. Unfortunately it will not raise a build error if anyone has any better ideas please let me know.
1: public class SomeClassName<T> where T : struct
2: {
3: public SomeClassName()
4: {
5: if (!typeof(T).IsEnum)
6: {
7: throw new ArgumentException("Parameter T must be of type Enum");
8: }
9: }
10: }