我创建了一个自定义属性:
[AttributeUsage(AttributeTargets.Method| AttributeTargets.Class)]
public class ActionAttribute : ActionFilterAttribute
{
public int Id { get; set; }
public string Work { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
[Area("Administrator")]
[Action(Id = 100, Work = "Test")]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
我的代码:我使用反射来查找当前程序集中的所有控制器
Assembly.GetEntryAssembly()
.GetTypes()
.AsEnumerable()
.Where(type => typeof(Controller).IsAssignableFrom(type))
.ToList()
.ForEach(d =>
{
// how to get ActionAttribute ?
});
Run Code Online (Sandbox Code Playgroud)
有可能以ActionAttribute实用的方式阅读所有内容吗?