如何调用SomeObject.SomeGenericInstanceMethod<T>(T arg)
?使用反射调用具有签名的对象实例的泛型方法:SomeObject.SomeGenericInstanceMethod <T>(T参数)
有一些关于调用泛型方法的文章,但不太像这个。问题是方法参数参数被限制为泛型参数。
我知道,如果签名是不是
SomeObject.SomeGenericInstanceMethod<T>(string arg)
那么我可以用
typeof (SomeObject).GetMethod("SomeGenericInstanceMethod", new Type[]{typeof (string)}).MakeGenericMethod(typeof(GenericParameter))
所以,我怎么去获取MethodInfo的时候经常得到的MethodInfo参数是一个泛型类型?谢谢!
另外,泛型参数可能有或没有类型限制。
[Select Right Generic Method with Reflection]的可能重复(http://stackoverflow.com/questions/3631547/select-right-generic-method-with-reflection) – nawfal 2014-01-17 15:22:17