我有一个 Controller 名称列表,然后会有一个给定 Controller (名称、GUID)中所有操作的列表。
找到的所有 Controller 列表 here .
我也在读 List all the actions on a controller with specific attribute这符合我的目的,因为我还需要具有特定属性的操作。但我只有所选 Controller 的名称/GUID,而不是对象本身。
我的场景:用户选择一个 Controller (级联下拉列表),然后从该 Controller 执行操作以配置一些访问(和链接)。因此,我只需要具有自定义属性的操作。
最佳答案
您可以继续使用反射,就像您在程序集中获取继承自 Controller 的类型一样。一旦你有了类型,你就可以枚举方法:
foreach(MethodInfo method in myContollerType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
{
}
然后,对于每个方法,您可以获得所有自定义属性:
foreach (var attribute in method.GetCustomAttributes(typeof(MyAttributeType),false))
{
}
关于c# - 特定 Controller 的操作列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1970388/