延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/
发布: 2008-9-25 10:20 | 作者: 不详 | 来源: 测试时代 采编 | 查看: 107次 | 进入软件测试论坛讨论
/// 运行实例方法 /// </summary> /// <param name="t"></param> /// <param name="strMethod"></param> /// <param name="objInstance"></param> /// <param name="aobjParams"></param> /// <returns></returns> public static object RunInstanceMethod(System.Type t, string strMethod, object objInstance, object[] aobjParams) { BindingFlags eFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; return RunMethod(t, strMethod, objInstance, aobjParams, eFlags); } /// <summary> /// 运行自定义方法 /// </summary> /// <param name="t"></param> /// <param name="strMethod"></param> /// <param name="objInstance"></param> /// <param name="aobjParams"></param> /// <param name="eFlags"></param> /// <returns></returns> private static object RunMethod(System.Type t, string strMethod, object objInstance, object[] aobjParams, BindingFlags eFlags) { MethodInfo m; try { m = t.GetMethod(strMethod, eFlags); if (m == null) { throw new ArgumentException("There is no method '" + strMethod + "' for type '" + t.ToString() + "'."); } object objRet = m.Invoke(objInstance, aobjParams); return objRet; } catch { throw; } } } // end of class } // end of namespace