我有一个控制器:
public class CatController
{
public something DoStuff([FromBody]string bibble)
{
}
}
我想创建一个ActionFilter并循环遍历每个参数,并查看该参数具有哪些属性,例如[FromBody]。我怎么能这样做?
public class InspectParametersActionFilter : ActionFilterAttribute, IActionFilter
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
actionContext.ActionDescriptor.?
actionContext.ActionArguments.?
}
}
答案 0 :(得分:2)
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var allCustomAttributes = filterContext.ActionDescriptor.GetParameters()
.Select(s => s.GetCustomAttributes(false));
}