【发布时间】:2017-09-24 11:00:38
【问题描述】:
在我的 MVC 5 控制器中,我经常放置一个类级别的自定义属性来管理用户访问权限,例如
[RoleAuthorize("CreditSlipLog")]
public class CreditLogCreditSumController : Controller
{
我想知道是否可以查询应用程序以列出我的应用程序中每个控制器类的现有属性(分布在多个区域)。
我知道如何编写 LINQ 查询,但我不知道要选择哪个对象。在伪代码中,我想像这样:
var list = (queryable list of areas, classes and their attributes)
.Where(controller has "RoleAuthorize" custom filter)
.Select(m=> new {
Area = m.Area,
Controller = m.ControllerName,
RoleAuthorizeValue = m.ControllerAttributeValue
}).ToList();
其中,“RoleAuthorizeValue”是[RoleAuthorize]的参数值
所以示例结果可能如下所示:
Area | Controller | RoleAuthorizeValue
------------------------------------------------------------
Credit | CreditLogCreditSumController | CreditSlipLog
我可以查询单个对象,还是查询会非常混乱?或者它甚至是可能的?虽然我可以手动执行此操作,但它是一个非常大的应用程序,并且仍会发生更改,这会使手动文档很快与应用程序中的任何更改不同步。
【问题讨论】:
-
您的所有类型都将包含在程序集中。查看
System.Reflection.Assembly.GetExecutingAssembly()。
标签: c# asp.net-mvc linq asp.net-mvc-5