Merge pull request #260 from pcc/topmost
[mono.git] / mcs / class / System.Web.Mvc3 / Mvc / Async / ReflectedAsyncControllerDescriptor.cs
1 namespace System.Web.Mvc.Async {
2     using System;
3     using System.Collections.Generic;
4
5     public class ReflectedAsyncControllerDescriptor : ControllerDescriptor {
6
7         private static readonly ActionDescriptor[] _emptyCanonicalActions = new ActionDescriptor[0];
8
9         private readonly Type _controllerType;
10         private readonly AsyncActionMethodSelector _selector;
11
12         public ReflectedAsyncControllerDescriptor(Type controllerType) {
13             if (controllerType == null) {
14                 throw new ArgumentNullException("controllerType");
15             }
16
17             _controllerType = controllerType;
18             _selector = new AsyncActionMethodSelector(_controllerType);
19         }
20
21         public sealed override Type ControllerType {
22             get {
23                 return _controllerType;
24             }
25         }
26
27         public override ActionDescriptor FindAction(ControllerContext controllerContext, string actionName) {
28             if (controllerContext == null) {
29                 throw new ArgumentNullException("controllerContext");
30             }
31             if (String.IsNullOrEmpty(actionName)) {
32                 throw Error.ParameterCannotBeNullOrEmpty("actionName");
33             }
34
35             ActionDescriptorCreator creator = _selector.FindAction(controllerContext, actionName);
36             if (creator == null) {
37                 return null;
38             }
39
40             return creator(actionName, this);
41         }
42
43         public override ActionDescriptor[] GetCanonicalActions() {
44             // everything is looked up dymanically, so there are no 'canonical' actions
45             return _emptyCanonicalActions;
46         }
47
48         public override object[] GetCustomAttributes(bool inherit) {
49             return ControllerType.GetCustomAttributes(inherit);
50         }
51
52         public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
53             return ControllerType.GetCustomAttributes(attributeType, inherit);
54         }
55
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);
60             }
61             return base.GetFilterAttributes(useCache);
62         }
63
64         public override bool IsDefined(Type attributeType, bool inherit) {
65             return ControllerType.IsDefined(attributeType, inherit);
66         }
67
68     }
69 }