类里有SQLExecuteQueryCollection的多外重载,我想调用类的这个重载方法,试了半天,没有成功。1.用getMethod
2.用InvokeMemberpublic IList<T> SQLExecuteQueryCollection<T,Tparam>( string sqlStatement , Tparam t )
where Tparam : class , new( )
where T : class , new( )
{}
2.用InvokeMemberpublic IList<T> SQLExecuteQueryCollection<T,Tparam>( string sqlStatement , Tparam t )
where Tparam : class , new( )
where T : class , new( )
{}
解决方案 »
- 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误
- 谁有打印机在注册表的devmode的每个位置的解释。
- radioButton自动执行Click事件的问题
- 如何获取另一个窗体中Panel里面StringBuilder sb = new StringBuilder();的控件
- 这段代码打印预览正常,但点打印预览里的打印按钮,打不出东西?
- 想用C#做一个组件来调用web service,给ASP页面来调用,该如何下手呢?
- 太奇怪了,高分求解,timer事件不执行
- C#的简单三维开发?
- ···
- 请问怎么样创建数据库??
- 编程新手,c#做火车站销售系统,不知从何下手,求指导
- 急,,,如何给html下拉列表绑定一项所有
GetMethod("SQLExecuteQueryCollection",new Type[]{})type[]中的参数如何指定。谢谢。
你连最基本的反射都不会啊!假设这个函数所在的类叫SqlHelper
那么得到这个函数的方法是:
System.Reflection.MethodInfo method = typeof(SqlHelper).GetMethod("SQLExecuteQueryCollection");
method = method.MakeGenericMethod(typeof(T), typeof(Tparam));
method.Invoke(...);
特别注意,这里面用的typeof(T), typeof(Tparam)并非实际类型,请实际使用时替换实际的类上去。
报错:
An unhandled exception of type 'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dllAdditional information: Ambiguous match found.因为SQLExecuteQueryCollection有很多重载关键是string sqlStatement , Tparam t 这两个参数如何放到GetMethod中。
这样就不会有重载的函数了。
System.Reflection.MethodInfo method = typeof(SqlHelper).GetMethod("SQLExecuteQueryCollection2");
method = method.MakeGenericMethod(typeof(T), typeof(Tparam));
method.Invoke(...);