I have a generic method which will return a select list populated from an enum.
public static IEnumerable<SelectListItem> GetGenericEnumSelectList<T>()
{
return (Enum.GetValues(typeof(T)).Cast<int>().Select(e => new SelectListItem() { Text = EnumExtensions.GetEnumDescription((ProductsEnum)e) , Value = e.ToString() })).ToList();
}
I have put a call to a static method I also have called GetEnumDescription
, this expects an Enum. How can I pass in the current type rather than hard coding the type as I have done. So that if T
is a different type of enum, it will be generic.
Something like:
public static IEnumerable<SelectListItem> GetGenericEnumSelectList<T>()
{
return (Enum.GetValues(typeof(T)).Cast<int>().Select(e => new SelectListItem() { Text = EnumExtensions.GetEnumDescription((typeof(T))e) , Value = e.ToString() })).ToList();
}
EDIT
Signature of GetEnumDescription
is
public static string GetEnumDescription(Enum value)
{
///
}