/// <summary>
        /// Gets a controller's route prefix URL.
        /// </summary>
        /// <param name="routePrefixAttribute">The <see cref="RoutePrefixAttribute"/> for the controller.</param>
        /// <param name="actionMethod">The <see cref="MethodInfo"/> for an action.</param>
        /// <param name="convention">The <see cref="RouteConventionAttributeBase"/> for the controller.</param>
        /// <returns>The route prefix URL to apply against the action.</returns>
        private static string GetRoutePrefix(RoutePrefixAttribute routePrefixAttribute, MethodInfo actionMethod, RouteConventionAttributeBase convention)
        {
            // Return an explicitly defined route prefix, if defined
            if (routePrefixAttribute != null)
            {
                return(routePrefixAttribute.Url);
            }

            // Otherwise, if this is a convention-based controller, get the convention-based prefix
            if (convention != null)
            {
                return(convention.GetDefaultRoutePrefix(actionMethod));
            }

            return(null);
        }
Beispiel #2
0
        private static IEnumerable <RoutePrefixAttribute> GetRoutePrefixAttributes(Type controllerType, RouteConventionAttributeBase convention, MethodInfo actionMethod)
        {
            // If there are any explicit route prefixes defined, use them.
            var routePrefixAttributes = controllerType.GetCustomAttributes <RoutePrefixAttribute>(true).ToList();

            // Otherwise apply conventional prefixes.
            if (!routePrefixAttributes.Any() && convention != null)
            {
                var oldConventionalRoutePrefix = convention.GetDefaultRoutePrefix(actionMethod);
                if (oldConventionalRoutePrefix.HasValue())
                {
                    routePrefixAttributes.Add(new RoutePrefixAttribute(oldConventionalRoutePrefix));
                }
                else
                {
                    routePrefixAttributes.AddRange(convention.GetDefaultRoutePrefixes(controllerType));
                }
            }

            return(routePrefixAttributes.OrderBy(a => GetSortableOrder(a.Precedence)));
        }
        private static IEnumerable<RoutePrefixAttribute> GetRoutePrefixAttributes(Type controllerType, RouteConventionAttributeBase convention, MethodInfo actionMethod)
        {
            // If there are any explicit route prefixes defined, use them.
            var routePrefixAttributes = controllerType.GetCustomAttributes<RoutePrefixAttribute>(true).ToList();

            // Otherwise apply conventional prefixes.
            if (!routePrefixAttributes.Any() && convention != null)
            {
                var oldConventionalRoutePrefix = convention.GetDefaultRoutePrefix(actionMethod);
                if (oldConventionalRoutePrefix.HasValue())
                {
                    routePrefixAttributes.Add(new RoutePrefixAttribute(oldConventionalRoutePrefix));
                }
                else
                {
                    routePrefixAttributes.AddRange(convention.GetDefaultRoutePrefixes(controllerType));
                }
            }

            return routePrefixAttributes.OrderBy(a => GetSortableOrder(a.Precedence));
        }
        /// <summary>
        /// Gets a controller's route prefix URL.
        /// </summary>
        /// <param name="routePrefixAttribute">The <see cref="RoutePrefixAttribute"/> for the controller.</param>
        /// <param name="actionMethod">The <see cref="MethodInfo"/> for an action.</param>
        /// <param name="convention">The <see cref="RouteConventionAttributeBase"/> for the controller.</param>
        /// <returns>The route prefix URL to apply against the action.</returns>
        private static string GetRoutePrefix(RoutePrefixAttribute routePrefixAttribute, MethodInfo actionMethod, RouteConventionAttributeBase convention)
        {
            // Return an explicitly defined route prefix, if defined
            if (routePrefixAttribute != null)
                return routePrefixAttribute.Url;

            // Otherwise, if this is a convention-based controller, get the convention-based prefix
            if (convention != null)
                return convention.GetDefaultRoutePrefix(actionMethod);

            return null;
        }