用反射处理Enum型变量
1 public class DynamicServiceEnum
2 {
3 private static string _enumName = string.Empty;
4 /// <summary>
5 /// Name of a enum
6 /// </summary>
7 public static string EnumName
8 {
9 get { return _enumName; }
10 set { _enumName = value; }
11 }
12
13 private static object InvokeEnum()
14 {
15 return DynamicServiceClass.InvokeWebservice(DynamicServiceEnum.EnumName);
16 }
17
18 public static int GetEnumItemValue(string enumItemName)
19 {
20 object enumObj = InvokeEnum();
21 FieldInfo enumItem = enumObj.GetType().GetField(enumItemName);
22 int result = (int)enumItem.GetValue(enumObj.GetType());
23
24 return result;
25 }
26 }
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!http://www.cnblogs.com/sunshine-anycall/archive/2009/01/07/1370876.html