Possible Duplicate:
Create Generic method constraining T to an Enum
is it possible to create a generic method that takes in any enum? I'll then check the incoming type to first make sure it's an enum that was passed (or can I enforce that natrually through the method definition?) and second then if it's an enum, I will have a bunch of case statements that do stuff based on what type of enum that was passed. So for example I can pass it CompanyColumns, PayColumns, etc. which are enums. My method needs to be able to take any enum like this and allow me to then work with the enum in my internal case statement.
public static DbType GetColumnDataType(I want to be able to pass in any object that's an enum)
public static void MyFunction<T>(T en) where T: IComparable, IFormattable, IConvertible
{
if (!typeof(T).IsEnum)
throw new ArgumentException("en must be enum type");
// implementation
}
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