2015-10-02 51 views
1

我有一個控制器:如何獲取ActionFilter中參數的所有屬性?

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.? 
    } 
} 

回答

2
public override void OnActionExecuting(ActionExecutingContext filterContext) 
{ 
    var allCustomAttributes = filterContext.ActionDescriptor.GetParameters() 
     .Select(s => s.GetCustomAttributes(false)); 
} 
相關問題