开发者

List of Actions for specific controller

I have a list of controller names and would then have a list of all actions in a given controller (name, GUID).

The list of all controllers found here.

I was also re开发者_如何转开发ading List all the actions on a controller with specific attribute which would match for my purposes as I also need actions with specific attributes. But I have only the name / GUID of the selected controller, not the object itself.

My scenario: the user selects a controller (cascading dropdown-list) and then actions from this controller to configure some access (and links). Therefore I need only the actions that have a custom attribute.


You can continue using Reflection just like you did to get the Types in your assembly that inherit from Controller. Once you have the Type, you can enumerate the methods:

foreach(MethodInfo method in myContollerType.GetMethods(BindingFlags.Public  | BindingFlags.Instance))
{

}

And, then for each method, you can get all the custom attributes:

foreach (var attribute in method.GetCustomAttributes(typeof(MyAttributeType),false))
{

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜