views:

20

answers:

1

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.

+1  A: 

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.

Darin Dimitrov
Yep, got that so far. I'm sort of stuck on how I should use that to make a URL.
Rei Miyasaka
So I ended up doing that and made a UrlExampleArgumentsAttribute that takes a param array of route values to send to Url.Action(). Not sure it's correct, but it works.
Rei Miyasaka