У меня есть следующие перечисления:Создать словарь из перечисления значений
public enum Brands
{
HP = 1,
IBM = 2,
Lenovo = 3
}
От этого я хочу сделать словарь в формате:
// key = name + "_" + id
// value = name
var brands = new Dictionary<string, string>();
brands[HP_1] = "HP",
brands[IBM_2] = "IBM",
brands[Lenovo_3] = "Lenovo"
До сих пор я сделал это, но есть трудности создание словаря по методу:
public static IDictionary<string, string> GetValueNameDict<TEnum>()
where TEnum : struct, IConvertible, IComparable, IFormattable
{
if (!typeof(TEnum).IsEnum)
throw new ArgumentException("TEnum must be an Enumeration type");
var res = from e in Enum.GetValues(typeof (TEnum)).Cast<TEnum>()
select // couldn't do this
return res;
}
Спасибо!