It is common to sometimes find generic methods of this type in its code:

public void MyMethod<T>(T input) where T : class
{
    // Some stuff here
}

I needed for a project to make a generic method for an Enum type. It seemed interesting to me to do something like:

public void MyMethod(T enumInput) where T : Enum
{
    // Some stuff here
}

However it turns out that this is not possible with the .Net 4 framework. After some research on the web I came across this proposal that I adopted and that I deliver to you. It assumes that an Enum implements the ‘IConvertible’ interface. On the other hand, it is necessary to make sure that you pass an Enum thanks to the typeof method.

Here an example :

public void MyMethod(T enumInput) where T : struct, IConvertible
{
    if (!typeof(T).IsEnum)
        throw new ArgumentException("T must be an Enum type.");
}