У меня есть класс enumHelper, который содержит:
public static IList<T> GetValues()
{
IList<T> list = new List<T>();
foreach (object value in Enum.GetValues(typeof(T)))
{
list.Add((T)value);
}
return list;
}
и
public static string Description(Enum value)
{
Attribute DescAttribute = LMIGHelper.GetAttribute(value, typeof(DescriptionAttribute));
if (DescAttribute == null)
return value.ToString();
else
return ((DescriptionAttribute)DescAttribute).Description;
}
мое перечисление выглядит примерно так:
public enum OutputType
{
File,
[Description("Data Table")]
DataTable
}
Все идет нормально. Все предыдущие работают нормально. Теперь я хочу добавить новый помощник для возврата BindingList>, чтобы я мог связать любое перечисление с любым комбо, используя
BindingList<KeyValuePair<OutputType, string>> list = Enum<OutputType>.GetBindableList();
cbo.datasource=list;
cbo.DisplayMember="Value";
cbo.ValueMember="Key";
Для этого я добавил:
public static BindingList<KeyValuePair<T, string>> GetBindingList()
{
BindingList<KeyValuePair<T, string>> list = new BindingList<KeyValuePair<T, string>>();
foreach (T value in Enum<T>.GetValues())
{
string Desc = Enum<T>.Description(value);
list.Add(new KeyValuePair<T, string>(value, Desc));
}
return list;
}
Но «Enum.Description (значение)» даже не компилируется: аргумент '1': невозможно преобразовать из 'T' в 'System.Enum'
Как я могу это сделать? Это вообще возможно?
Спасибо.