1 public class BaseMethod
2 {
3 public Hashtable GetMethodAttribute(T t)
4 {
5 var hashtable = new Hashtable();
6 Type type = t.GetType();
7 foreach (MethodInfo method in type.GetMethods())
8 {
9 var methodArray = (MethodAttribute[]) method.GetCustomAttributes(typeof (MethodAttribute), false);
10 foreach (MethodAttribute actionMethodAttribute in methodArray)
11 {
12 ActionEnum actiOnName= actionMethodAttribute.MethodName;
13 hashtable.Add(actionName, method);
14 }
15 }
16 return hashtable;
17 }
18
19
20 public string DoAction(ActionEnum actionName,string str) {
21 Hashtable ht = GetMethodAttribute(this);
22 string message = ht.Contains(actionName)
23 ? ((MethodInfo) ht[actionName]).Invoke(this, new object[] {str}).ToString()
24 : string.Format("{0} 超过范围", actionName);
25 return message;
26 }
27 }