コード例 #1
0
        /// <summary>Initializes a new instance of the <see cref="DirectRouteFactoryContext"/></summary>
        /// <param name="areaPrefix">The route prefix, if any, defined by the area.</param>
        /// <param name="controllerPrefix">The route prefix, if any, defined by the controller.</param>
        /// <param name="actions">The action descriptors to which to create a route.</param>
        /// <param name="inlineConstraintResolver">The inline constraint resolver.</param>
        /// <param name="targetIsAction">
        /// A value indicating whether the route is configured at the action or controller level.
        /// </param>
        public DirectRouteFactoryContext(
            string areaPrefix,
            string controllerPrefix,
            IReadOnlyCollection <ActionDescriptor> actions,
            IInlineConstraintResolver inlineConstraintResolver,
            bool targetIsAction
            )
#endif
        {
            if (actions == null)
            {
                throw new ArgumentNullException("actions");
            }

            if (inlineConstraintResolver == null)
            {
                throw new ArgumentNullException("inlineConstraintResolver");
            }

#if ASPNETWEBAPI
            _prefix = prefix;
#else
            _areaPrefix       = areaPrefix;
            _controllerPrefix = controllerPrefix;
#endif
            _actions = actions;
            _inlineConstraintResolver = inlineConstraintResolver;

            TActionDescriptor firstDescriptor = actions.FirstOrDefault();

            if (firstDescriptor != null)
            {
                _actionName = firstDescriptor.ActionName;
#if !ASPNETWEBAPI
                ControllerDescriptor controllerDescriptor = firstDescriptor.ControllerDescriptor;

                if (controllerDescriptor != null)
                {
                    _controllerName = controllerDescriptor.ControllerName;
                }
#endif
            }

            _targetIsAction = targetIsAction;
        }
コード例 #2
0
        protected override IReadOnlyList <IDirectRouteFactory> GetActionRouteFactories(System.Web.Http.Controllers.HttpActionDescriptor actionDescriptor)
        {
            var slimApiAction = actionDescriptor as SlimApiActionDescriptor;

            if (slimApiAction != null)
            {
                return(slimApiAction.RouteFactories.ToArray());
            }
            return(base.GetActionRouteFactories(actionDescriptor).ToList());
        }