2013-05-26 22 views

回答

1

您可以使用反射:

// arrange 
Expression<Action<HomeController>> expression = (HomeController c) => c.Index(); 
var mc = expression.Body as MethodCallExpression; 

// act 
var actual = mc.Method.GetCustomAttributes(typeof(MyActionFilterAttribute), false); 

// assert 
Assert.IsTrue(actual.Any()); 

這證實了MyActionFilterAttribiute已被用來裝飾家庭控制器上的索引操作:

public class HomeController: Controller 
{ 
    [MyActionFilter] 
    public ActionResult Index() 
    { 
     ... 
    } 
} 
+0

謝謝!我該如何檢查ASP.NET MVC3中CONTROLLER(而不是action)ActionFilterAttribute的可用性? –

+0

同樣的方法,使用反射。 –

相關問題