I'm working on an a tool to create an expression proxy generating mvc routes without looking up the route names manually. In the past i've provided this information manually through attributes on the given route.
However i'm wondering if there is a method to obtain this information given by the MVC framework.
So let's imagine this scenario:
public class SomeController : ApiController
{
public int SomeMethod(int someParam1, string someParam2)
{
}
}
var methodInfo = typeof(SomeController).GetMethod("SomeMethod");
var result = ImaginaryMethod(methodInfo); // Should return ["someParam1", "someParam2"]
I was wondering if there is a way to obtain argument names through for example the MethodInfo of a method or some other way.
Is there some framework method which already does that, which i am not aware of?
GetParameters
of MethodInfo
provides all information about method's parameters, so another method which returns only their names is probably unnecessary.
for e.g.:
public static string[] ImaginaryMethod(System.Reflection.MethodInfo method)
{
return method != null ? method.GetParameters().Select(p => p.Name).ToArray() : new string[0];
}