Bab*_*mes 6 asp.net-mvc custom-attributes
请考虑以下代码:
public class MyAttribute : Attribute { }
[MyAttribute]
public class MyControlller : Controller
{
//...
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个Global Action Filter让我得到一个ActionExecutingContext对象的东西.
我的问题是,在这里,我如何检查请求Controller是否已使用我的自定义进行装饰Attribute.
ide*_*ain 11
尝试
actionExecutingContextInstance.Controller.GetType().GetCustomAttributes(typeof(MyAttribute), false).Length > 0)
Run Code Online (Sandbox Code Playgroud)
要么
actionExecutingContextInstance.ActionDescriptor.GetCustomAttributes(typeof(MyAttribute), false).Length > 0)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4953 次 |
| 最近记录: |