1 namespace System.Web.Mvc.Async {
3 using System.Collections.Generic;
5 public class ReflectedAsyncControllerDescriptor : ControllerDescriptor {
7 private static readonly ActionDescriptor[] _emptyCanonicalActions = new ActionDescriptor[0];
9 private readonly Type _controllerType;
10 private readonly AsyncActionMethodSelector _selector;
12 public ReflectedAsyncControllerDescriptor(Type controllerType) {
13 if (controllerType == null) {
14 throw new ArgumentNullException("controllerType");
17 _controllerType = controllerType;
18 _selector = new AsyncActionMethodSelector(_controllerType);
21 public sealed override Type ControllerType {
23 return _controllerType;
27 public override ActionDescriptor FindAction(ControllerContext controllerContext, string actionName) {
28 if (controllerContext == null) {
29 throw new ArgumentNullException("controllerContext");
31 if (String.IsNullOrEmpty(actionName)) {
32 throw Error.ParameterCannotBeNullOrEmpty("actionName");
35 ActionDescriptorCreator creator = _selector.FindAction(controllerContext, actionName);
36 if (creator == null) {
40 return creator(actionName, this);
43 public override ActionDescriptor[] GetCanonicalActions() {
44 // everything is looked up dymanically, so there are no 'canonical' actions
45 return _emptyCanonicalActions;
48 public override object[] GetCustomAttributes(bool inherit) {
49 return ControllerType.GetCustomAttributes(inherit);
52 public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
53 return ControllerType.GetCustomAttributes(attributeType, inherit);
56 internal override IEnumerable<FilterAttribute> GetFilterAttributes(bool useCache) {
57 if (useCache && GetType() == typeof(ReflectedAsyncControllerDescriptor)) {
58 // Do not look at cache in types derived from this type because they might incorrectly implement GetCustomAttributes
59 return ReflectedAttributeCache.GetTypeFilterAttributes(ControllerType);
61 return base.GetFilterAttributes(useCache);
64 public override bool IsDefined(Type attributeType, bool inherit) {
65 return ControllerType.IsDefined(attributeType, inherit);