나는 오버로드 된 메서드가 거의없는 클래스가 있습니다. 그 매개 변수의 유형별로 특정 것을 얻으려고합니다. 처음 두 개 (int 및 string 형식의 인수 사용)를 사용하면 비교적 쉽습니다. 그러나 내가 무엇을 하든지 내 프로그램이 제네릭 목록을위한 제 3의 프로그램에 주목할 수는 없습니다. 잘못된 Type 인수를 사용합니까? 그렇다면 올바른 방법은 무엇입니까?C# : 형식 (일반 목록)으로 GetMethod
/* rest of code */
static void Main(string[] args) {
MethodInfo method =
typeof(c).GetMethod("m", new Type[] { typeof(int) });
Console.WriteLine(method);
method =
typeof(c).GetMethod("m", new Type[] { typeof(String) });
Console.WriteLine(method);
method =
typeof(c).GetMethod("m", new Type[] { typeof(IEnumerable<>) });
Console.WriteLine(method);
Console.ReadKey();
}
}
static class c
{
public static void m<T>(int i)
{
}
public static void m<T>(String s)
{
}
public static void m<T>(IEnumerable<T> Ls)
{
}
}
[리플렉션을 사용하여 일반적인 방법을 호출하는 방법은 무엇입니까?] (http://stackoverflow.com/questions/232535/how-do-i-use-reflection-to -call-a-generic-method) – CSharpie
@CSharpie 제네릭 메서드 자체를 얻는 방법에 대한 질문이 더 많습니다. 참조하는 질문에 대한 대답은 실제로 다루지 않습니다. – strongbutgood