Exemplo n.º 1
0
        /// <summary>
        /// Builds a <see cref="RouteSpecification"/> from component parts.
        /// </summary>
        /// <param name="controllerIndex">The index of this controller inthe registered controller types.</param>
        /// <param name="controllerType">The controller type.</param>
        /// <param name="actionMethod">The action method info.</param>
        /// <param name="routeAreaAttribute">An applicable <see cref="RouteAreaAttribute"/> for the controller.</param>
        /// <param name="routePrefixAttribute">An applicable <see cref="RoutePrefixAttribute"/> for the controller.</param>
        /// <param name="routeAttribute">The <see cref="IRouteAttribute"/> for the action.</param>
        /// <returns>The route specification.</returns>
        private RouteSpecification BuildRouteSpecification(int controllerIndex, Type controllerType, MethodInfo actionMethod, RouteAreaAttribute routeAreaAttribute, RoutePrefixAttribute routePrefixAttribute, IRouteAttribute routeAttribute, RouteVersionedAttribute routeVersionedAttribute)
        {
            var isAsyncController = controllerType.IsAsyncController();
            var subdomain = GetAreaSubdomain(routeAreaAttribute);
            var actionName = GetActionName(actionMethod, isAsyncController);

            return new RouteSpecification
            {
                ActionMethod = actionMethod,
                ActionName = actionName,
                ActionPrecedence = GetSortableOrder(routeAttribute.ActionPrecedence),
                AppendTrailingSlash = routeAttribute.AppendTrailingSlashFlag,
                AreaName = GetAreaName(routeAreaAttribute, controllerType),
                AreaUrl = GetAreaUrl(routeAreaAttribute, subdomain, controllerType),
                AreaUrlTranslationKey = routeAreaAttribute.SafeGet(a => a.TranslationKey),
                ControllerIndex = controllerIndex,
                ControllerName = controllerType.GetControllerName(),
                ControllerPrecedence = GetSortableOrder(routeAttribute.ControllerPrecedence),
                ControllerType = controllerType,
                HttpMethods = routeAttribute.HttpMethods,
                IgnoreAreaUrl = routeAttribute.IgnoreAreaUrl,
                IgnoreRoutePrefix = routeAttribute.IgnoreRoutePrefix,
                IsAbsoluteUrl = routeAttribute.IsAbsoluteUrl,
                PrefixPrecedence = GetSortableOrder(routePrefixAttribute.SafeGet(a => a.Precedence, int.MaxValue)),
                PreserveCaseForUrlParameters = routeAttribute.PreserveCaseForUrlParametersFlag,
                RouteName = routeAttribute.RouteName,
                RoutePrefixUrl = GetRoutePrefixUrl(routePrefixAttribute, controllerType),
                RoutePrefixUrlTranslationKey = routePrefixAttribute.SafeGet(a => a.TranslationKey),
                RouteUrl = routeAttribute.RouteUrl ?? actionName,
                RouteUrlTranslationKey = routeAttribute.TranslationKey,
                SitePrecedence = GetSortableOrder(routeAttribute.SitePrecedence),
                Subdomain = subdomain,
                UseLowercaseRoute = routeAttribute.UseLowercaseRouteFlag,
                IsVersioned = routeVersionedAttribute != null && routeVersionedAttribute.IsVersioned,
                MinVersion = routeAttribute.MinVersion ?? (routeVersionedAttribute != null ? routeVersionedAttribute.MinVersion : null),
                MaxVersion = routeAttribute.MaxVersion ?? (routeVersionedAttribute != null ? routeVersionedAttribute.MaxVersion : null)
            };
        }