开发者

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 acti开发者_JAVA技巧on.

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜