protected ActionParameterInfo(ActionInfo action)
 {
     this.Action = action;
 }
 public ReflectedMvcActionParameterInfo(ParameterInfo paramInfo, ActionInfo action)
     : base(action)
 {
     this.paramInfo = paramInfo;
 }
 public DescribedHttpActionParameterInfo(HttpParameterDescriptor paramDescr, ActionInfo action)
     : base(action)
 {
     this.paramDescr          = paramDescr;
     this.reflectedParamDescr = this.paramDescr as ReflectedHttpParameterDescriptor;
 }
Ejemplo n.º 4
0
 protected ActionParameterInfo(ActionInfo action)
 {
     this.Action = action;
 }
Ejemplo n.º 5
0
        void CheckDefaultActions(IEnumerable <ActionInfo> actions)
        {
            // - Index is the default action by convention
            // - You can use [DefaultAction] to override the convention
            //   - Can only be applied to one action per controller type
            //   - Can be inherited from base controller
            //   - Derived controllers can override the inherited [DefaultAction] by applying it to a different action
            // - Default action cannot have required route parameters (either no parameters or all optional)

            Func <ActionInfo, bool> correctRouteParameterSetup = a =>
                                                                 a.RouteParameters.Count == 0 ||
                                                                 a.RouteParameters.All(p => p.IsOptional);

            ActionInfo defaultAction = null;

            Type attrType = this.Provider.DefaultActionAttributeType;

            if (attrType != null)
            {
                var defaultActions =
                    (from a in actions
                     where a.GetCustomAttributes(attrType, inherit: false).Any()
                     select a).ToArray();

                if (defaultActions.Any())
                {
                    var byDeclaringType =
                        from a in defaultActions
                        group a by a.DeclaringType;

                    if (defaultActions.Length > byDeclaringType.Count())
                    {
                        throw new InvalidOperationException(
                                  "{0} can only be used once per declaring type: {1}.".FormatInvariant(attrType.FullName, byDeclaringType.First(g => g.Count() > 1).Key.FullName)
                                  );
                    }

                    for (Type t = this.Type; t != null; t = t.BaseType)
                    {
                        defaultAction = defaultActions.SingleOrDefault(a => a.DeclaringType == t);

                        if (defaultAction != null)
                        {
                            if (!correctRouteParameterSetup(defaultAction))
                            {
                                throw new InvalidOperationException(
                                          "Default actions cannot have required route parameters: {0}.".FormatInvariant(
                                              String.Concat(defaultAction.DeclaringType.FullName, ".", defaultAction.MethodName, "(", String.Join(", ", defaultAction.Parameters.Select(p => p.Type.Name)), ")")
                                              )
                                          );
                            }

                            break;
                        }
                    }
                }
            }

            if (defaultAction == null)
            {
                defaultAction = actions.FirstOrDefault(a => ActionInfo.NameEquals(a.Name, "Index") && correctRouteParameterSetup(a));
            }

            if (defaultAction != null)
            {
                defaultAction.IsDefaultAction = true;
            }
        }
 public DescribedMvcActionParameterInfo(ParameterDescriptor paramDescr, ActionInfo action)
     : base(action)
 {
     this.paramDescr = paramDescr;
      this.reflectedParamDescr = paramDescr as ReflectedParameterDescriptor;
 }