1         public static int GetEnumValue(Type enumType, string enumName)
 2         {
 3             try
 4             {
 5                 if (!enumType.IsEnum)
 6                     throw new ArgumentException("enumType必须是枚举类型");
 7                 var values = Enum.GetValues(enumType);
 8                 var ht = new Hashtable();
 9                 foreach(var val in values)
10                 {
11                     ht.Add(Enum.GetName(enumType, val), val);
12                 }
13                 return (int)ht[enumName];
14             }
15             catch (Exception e)
16             {
17                 throw e;
18             }
19         }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
相关资源
相似解决方案