Assuming there exist a class X as described below, how do I get method information for the non-generic method? The code below will throw an exception.
using System;
class Program {
static void Main(string[] args) {
var mi = Type.GetType("X").GetMethod("Y"); // Ambiguous match found.
Console.WriteLine(mi.ToString());
}
}
class X {
public void Y() {
Console.WriteLine("I want this one");
}
public void Y<T>() {
Console.WriteLine("Not this one");
}
}
Don’t use
GetMethod, useGetMethods, then checkIsGenericMethod.As a bonus – an extension method:
Then just: