如何調用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