I have this type that contains two overloads of a generic method. I like to retrieve one of the overloads (with the Func
parameter) using reflection. T
Why don't you use expression trees? This makes it much easier:
public static MethodInfo GetMethod(
Expression> methodSelector)
{
var body = (MethodCallExpression)methodSelector.Body;
return body.Method;
}
[TestMethod]
public void Test1()
{
var expectedMethod = typeof(Foo)
.GetMethod("Bar", new Type[] { typeof(Func<>) });
var actualMethod =
GetMethod(foo => foo.Bar