연장 방법 GenericExtension
을 작성했습니다. 이제 확장 메서드 Extension
을 호출하고 싶습니다. 그러나 methodInfo
값은 항상 null입니다.리플렉션을 사용하여 일반 확장 메소드를 호출하는 방법은 무엇입니까?
public static class MyClass
{
public static void GenericExtension<T>(this Form a, string b) where T : Form
{
// code...
}
public static void Extension(this Form a, string b, Type c)
{
MethodInfo methodInfo = typeof(Form).GetMethod("GenericExtension", new[] { typeof(string) });
MethodInfo methodInfoGeneric = methodInfo.MakeGenericMethod(new[] { c });
methodInfoGeneric.Invoke(a, new object[] { a, b });
}
private static void Main(string[] args)
{
new Form().Extension("", typeof (int));
}
}
뭐가 잘못 되었나요?
참조 http://stackoverflow.com/questions/5959219/how 그것에 대한 자세한 정보는 -to-use-reflection-to-get-extension-method-generic-type? rq = 1을 참조하십시오. – skarmats