제네릭 메서드의 MethodInfo를 비 제네릭 형식으로 되돌리려면 어떤 인수를 Type.GetMethod에 전달해야하는지 알 수없는 작은 문제가 있습니다. 은 특히,이 유형 정의가 : 나는 여러 가지 시도 Type.GetMethod에서 소요 한generic이 아닌 .NET 유형에서 일반 메소드의 MethodInfo를 얻는 방법은 무엇입니까?
public static class A
{
public static B F<T>(bool dummy)
{
}
public static B F<T>(IEnumerable<T> arg)
{
...
}
}
을, 그러나 아무도는 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)
시도한 코드를 게시하십시오. –
내 질문이 변경되었습니다. 감사. – mark
@ 마크 대답을 바꿨습니다. –