I've got some code (for helping with url routing) that tries to find an action method in a controller.
My controller looks like so:
public ActionResult Item(int id)
{
MyViewModel model = new MyViewModel(id);
return View(model);
}
[HttpPost]
public ActionResult Item(MyViewModel model)
{
//do other stuff here
return View(model);
}
The following code attempts to find a method matching the url action:
//cont is a System.Type object representing the controller
MethodInfo actionMethod = cont.GetMethod(action);
Today this code threw a System.Reflection.AmbiguousMatchException: Ambiguous match found
which makes sense given my two methods have the same name.
I took a look at the available methods of the Type
object and found public MethodInfo[] GetMethods();
which seems to do what I want, except there doesn't seem to be an overload for searching for a method with a specific name.
I could just use this method and search everything it returns, but I'm wondering if there's another (simpler) way to obtain a list of all methods in a class with a specific name, when there are multiple.