Rei Miyasaka
Rei Miyasaka

Reputation: 7116

URL from action method name or MethodInfo or something, or listing action routes

I'm trying to document all the actions in my web app, and one of the things I want do is to provide a sample URL for an action.

Is there a way to list all the actions in a website along with their routes, or maybe a way to find the route from a MethodInfo?

I'm thinking I might have to write a custom attribute for each action to specify dummy values to use for actions with parameters.

Upvotes: 0

Views: 493

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

You could easily get all the actions using reflection:

var actions = 
    from controller in Assembly.GetExecutingAssembly().GetTypes()
    where typeof(Controller).IsAssignableFrom(controller)
    from action in controller.GetMethods()
    where typeof(ActionResult).IsAssignableFrom(action.ReturnType)
    select new { Controller = controller, Action = action };

Adapt to include the assemblies you are interested in.

Upvotes: 1

Related Questions