protected IDictionary<int, string> GetAll<TEnum>() where TEnum : struct
{
var enumerationType = typeof(TEnum);
if (!enumerationType.IsEnum)
throw new ArgumentException("Enumeration type is expected.");
var dictionary = new Dictionary<int, string>();
foreach (int value in Enum.GetValues(enumerationType))
{
var name = Enum.GetName(enumerationType, value);
dictionary.Add(value, name);
}
return dictionary;
}
转换枚举类到集合,用于绑定到控件
最新推荐文章于 2025-04-29 16:34:17 发布
本文介绍了一个实用的方法,用于将枚举类型转换为字典,其中键为枚举的整数值,值为枚举成员的名称。这种方法适用于.NET平台,并且能够方便地获取枚举的所有成员及其对应的值。
1230

被折叠的 条评论
为什么被折叠?



