1

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 reading 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.

Community
  • 1
  • 1
griti
  • 650
  • 8
  • 23

1 Answers1

6

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))
{

}
BFree
  • 102,548
  • 21
  • 159
  • 201