c# - 特定 Controller 的操作列表

标签 c# asp.net-mvc

我有一个 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/

相关文章:

c# - 将日期时间模型属性显示为短日期时间字符串

asp.net-mvc - ASP.NET MVC Textbox HtmlHelper 的 NullReferenceException 问题

c# - DataContractSerializer 跳过 OpenAccess 版本的值

c# - 多页 PrintDocument 中的不同方向(如何)

c# - 如何将表达式 Func<T, object[]> 转换为 Func<T, object>

c# - sql存储过程与代码,对于大量数据,哪个更好?

javascript - Angularjs Kendo 主从网格应用主从的默认 ID 以添加新的详细记录

c# - 使用 MongoDB C# 查找和修改

c# - jQuery中onclick方法中调用服务器端方法

.net - 有没有办法在不安装的情况下引用ghostscript DLL?