public class TestClass<T> { public void TestMethod(T t1) { } public void TestMethod(int t1) { } void Question() { TestClass<string> tc1 = new TestClass<string>(); MethodInfo method1 = new Action<string>(tc1.TestMethod).Method; TestClass<int> tc2 = new TestClass<int>(); MethodInfo method2 = new Action<int>(tc2.TestMethod).Method; MethodInfo method3 = new Func<MethodInfo, Type, MethodInfo>(delegate(MethodInfo genericMethod, Type genericArgument) { //If I got method2, is there any way to get method1 if I provides method2 and a type parameter of 'string' return null; })(method2, typeof(string)); tc2.TestMethod(1);//The method will call TestMethod(int t1), how to call TestMethod(T t1) instead. } }
I have two question.
Question 1:
If I got a method info from a generic type, and a generic type argument, can I get the same method info of new generic type from original type's generic definition?
Question 2:
As you see, there is a conflicte in TestMethod if I call TestClass<int>'s method, how to call the correct method?