So I need to write a method that does a lookup. It needs to take an enum generic and then convert the enum value to a string and return it
This is what I have so far
public static object lookupColumn<TEnum>(int? id, string defaultValue="")
where TEnum : struct, IConvertible
{
if (!(typeof(TEnum).IsEnum))
throw new ArgumentException("TEnum must be of type Enum");
if (!id.HasValue)
return defaultValue;
TEnum enumValue = (TEnum) id.Value; //This line doesn't compile
return enumValue.ToString();
}
Any suggestions?
EDIT: The part that is causing me trouble is casting the int to an enum