我有一个小问题,就是我不知道在Type.GetMethod中传递哪些参数才能够获取非泛型类型上的泛型方法的MethodInfo。 具体来说,我有以下类型定义:
public static class A
{
public static B F<T>(bool dummy)
{
}
public static B F<T>(IEnumerable<T> arg)
{
...
}
}
我已经尝试了几种Type.GetMethod的方法,但是没有一种能够返回F方法的MethodInfo。
我知道可以调用Type.GetMethods甚至Type.FindMember,但我只对Type.GetMethod感兴趣。
有什么想法吗?
谢谢。
编辑
实际上,我的代码有点复杂。这个泛型方法是重载的,所以我不能只使用函数名来调用Type.GetMethod。 我尝试了这些变体:
typeof(A).GetMethod("F", BindingFlags.Static | BindingFlags.Public, null, new Type[]{ typeof(IEnumerable<>) }, null)
typeof(A).GetMethod("F`1", BindingFlags.Static | BindingFlags.Public, null, new Type[]{ typeof(IEnumerable<>) }, null)
typeof(A).GetMethod("F[T]", BindingFlags.Static | BindingFlags.Public, null, new Type[]{ typeof(IEnumerable<>) }, null)
typeof(A).GetMethod("F[[T]]", BindingFlags.Static | BindingFlags.Public, null, new Type[]{ typeof(IEnumerable<>) }, null)