private static ICollection<RouteDefaultAttribute> GetDefaultAttributes(MethodInfo actionMethod, string routeName, RouteConventionAttributeBase convention) { var defaultAttributes = new List<RouteDefaultAttribute>(); // Yield explicitly defined default attributes first defaultAttributes.AddRange( from defaultAttribute in actionMethod.GetCustomAttributes<RouteDefaultAttribute>(false) where !defaultAttribute.ForRouteNamed.HasValue() || defaultAttribute.ForRouteNamed == routeName select defaultAttribute); // Yield convention-based defaults next if (convention != null) defaultAttributes.AddRange(convention.GetRouteDefaultAttributes(actionMethod)); return defaultAttributes.ToList(); }
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<IRouteAttribute> GetRouteAttributes(MethodInfo actionMethod, RouteConventionAttributeBase convention) { var attributes = new List<IRouteAttribute>(); // Add convention-based attributes if (convention != null) { attributes.AddRange(convention.GetRouteAttributes(actionMethod)); } // Add explicitly-defined attributes attributes.AddRange(actionMethod.GetCustomAttributes<IRouteAttribute>(false)); return attributes; }
private static RouteAreaAttribute GetRouteAreaAttribute(Type controllerType, RouteConventionAttributeBase convention) { return controllerType.GetCustomAttribute<RouteAreaAttribute>(true) ?? convention.SafeGet(x => x.GetDefaultRouteArea(controllerType)); }
/// <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; }
/// <summary> /// Get a <see cref="RouteVersionedAttribute"/> to use for the controller. /// </summary> /// <param name="controllerType">The controller type.</param> /// <param name="convention">An applicable <see cref="RouteConventionAttributeBase"/> for the controller.</param> /// <returns>An applicable <see cref="RouteAreaAttribute"/>.</returns> private static RouteVersionedAttribute GetRouteVersionedAttribute(Type controllerType, RouteConventionAttributeBase convention) { return controllerType.GetCustomAttribute<RouteVersionedAttribute>(true); }
/// <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); }
/// <summary> /// Gets the route attributes for an action. /// </summary> /// <param name="actionMethod">The <see cref="MethodInfo"/> for the action.</param> /// <param name="convention">The <see cref="RouteConventionAttributeBase"/> applied to the action's controller.</param> /// <returns>The route attributes for the action.</returns> private static IEnumerable <IRouteAttribute> GetRouteAttributes(MethodInfo actionMethod, RouteConventionAttributeBase convention) { var attributes = new List <IRouteAttribute>(); // Add convention-based attributes if (convention != null) { attributes.AddRange(convention.GetRouteAttributes(actionMethod)); } // Add explicitly-defined attributes attributes.AddRange(actionMethod.GetCustomAttributes <IRouteAttribute>(false)); return(attributes); }
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 RouteAreaAttribute GetRouteAreaAttribute(Type controllerType, RouteConventionAttributeBase convention) { return(controllerType.GetCustomAttribute <RouteAreaAttribute>(true) ?? convention.SafeGet(x => x.GetDefaultRouteArea(controllerType))); }
private static ICollection <RouteConstraintAttributeBase> GetConstraintAttributes(MethodInfo actionMethod, string routeName, RouteConventionAttributeBase convention) { var constraintAttributes = new List <RouteConstraintAttributeBase>(); // Yield explicitly defined constraint attributes first constraintAttributes.AddRange( from constraintAttribute in actionMethod.GetCustomAttributes <RouteConstraintAttributeBase>(false) where !constraintAttribute.ForRouteNamed.HasValue() || constraintAttribute.ForRouteNamed == routeName select constraintAttribute); // Yield convention-based constraints next if (convention != null) { constraintAttributes.AddRange(convention.GetRouteConstraintAttributes(actionMethod)); } return(constraintAttributes.ToList()); }