/// <summary>Creates a route builder that can build a route matching this context.</summary> /// <param name="template">The route template.</param> /// <param name="constraintResolver"> /// The inline constraint resolver to use, if any; otherwise, <see langword="null"/>. /// </param> /// <returns>A route builder that can build a route matching this context.</returns> public IDirectRouteBuilder CreateBuilder(string template, IInlineConstraintResolver constraintResolver) { DirectRouteBuilder builder = new DirectRouteBuilder(_actions, _targetIsAction); #if ASPNETWEBAPI string prefixedTemplate = BuildRouteTemplate(_prefix, template); #else string prefixedTemplate = BuildRouteTemplate(_areaPrefix, _controllerPrefix, template ?? String.Empty); #endif ValidateTemplate(prefixedTemplate); if (constraintResolver != null) { TRouteDictionary defaults = new TRouteDictionary(); TRouteDictionary constraints = new TRouteDictionary(); string detokenizedTemplate = InlineRouteTemplateParser.ParseRouteTemplate(prefixedTemplate, defaults, constraints, constraintResolver); TParsedRoute parsedRoute = RouteParser.Parse(detokenizedTemplate); decimal precedence = RoutePrecedence.Compute(parsedRoute, constraints); builder.Defaults = defaults; builder.Constraints = constraints; builder.Template = detokenizedTemplate; builder.Precedence = precedence; builder.ParsedRoute = parsedRoute; } else { builder.Template = prefixedTemplate; } return(builder); }
internal virtual DirectRouteBuilder CreateBuilder(string template, IInlineConstraintResolver constraintResolver) { DirectRouteBuilder builder = new DirectRouteBuilder(_actions); string prefixedTemplate = BuildRouteTemplate(_prefix, template); Contract.Assert(prefixedTemplate != null); if (prefixedTemplate.StartsWith("/", StringComparison.Ordinal)) { throw Error.InvalidOperation(SRResources.AttributeRoutes_InvalidTemplate, template, _actionName); } if (constraintResolver != null) { builder.Defaults = new HttpRouteValueDictionary(); builder.Constraints = new HttpRouteValueDictionary(); builder.Template = InlineRouteTemplateParser.ParseRouteTemplate(prefixedTemplate, builder.Defaults, builder.Constraints, constraintResolver); builder.ParsedRoute = HttpRouteParser.Parse(builder.Template); builder.Precedence = RoutePrecedence.Compute(builder.ParsedRoute, builder.Constraints); } else { builder.Template = prefixedTemplate; } return(builder); }
private static decimal Compute(string template) { DefaultInlineConstraintResolver resolver = new DefaultInlineConstraintResolver(); HttpRouteValueDictionary defaults = new HttpRouteValueDictionary(); HttpRouteValueDictionary constraints = new HttpRouteValueDictionary(); string standardRouteTemplate = InlineRouteTemplateParser.ParseRouteTemplate(template, defaults, constraints, new DefaultInlineConstraintResolver()); HttpParsedRoute parsedRoute = HttpRouteParser.Parse(standardRouteTemplate); return(RoutePrecedence.Compute(parsedRoute, constraints)); }
private ParseResult Act(string template) { var result = new ParseResult(); #if ASPNETWEBAPI result.Constraints = new HttpRouteValueDictionary(); result.Defaults = new HttpRouteValueDictionary(); #else result.Constraints = new RouteValueDictionary(); result.Defaults = new RouteValueDictionary(); #endif result.RouteUrl = InlineRouteTemplateParser.ParseRouteTemplate(template, result.Defaults, result.Constraints, new DefaultInlineConstraintResolver()); return(result); }
/// <summary> /// Builds an <see cref="IHttpRoute"/> for a particular action. /// </summary> /// <param name="routeTemplate">The tokenized route template for the route.</param> /// <param name="actions">The actions to invoke for the route.</param> /// <returns>The generated <see cref="IHttpRoute"/>.</returns> public virtual IHttpRoute BuildHttpRoute( string routeTemplate, IEnumerable <ReflectedHttpActionDescriptor> actions) { if (routeTemplate == null) { throw Error.ArgumentNull("routeTemplate"); } HttpRouteValueDictionary defaults = new HttpRouteValueDictionary(); HttpRouteValueDictionary constraints = new HttpRouteValueDictionary(); string detokenizedRouteTemplate = InlineRouteTemplateParser.ParseRouteTemplate(routeTemplate, defaults, constraints, ConstraintResolver); return(BuildHttpRoute(detokenizedRouteTemplate, defaults, constraints, actions)); }
/// <summary> /// Builds an <see cref="IHttpRoute"/> for a particular action. /// </summary> /// <param name="routeTemplate">The tokenized route template for the route.</param> /// <param name="httpMethods">The HTTP methods supported by the route.</param> /// <param name="actions">The actions to invoke for the route.</param> /// <returns>The generated <see cref="IHttpRoute"/>.</returns> public virtual IHttpRoute BuildHttpRoute( string routeTemplate, IEnumerable <HttpMethod> httpMethods, IEnumerable <ReflectedHttpActionDescriptor> actions) { if (routeTemplate == null) { throw Error.ArgumentNull("routeTemplate"); } HttpRouteValueDictionary defaults = new HttpRouteValueDictionary(); HttpRouteValueDictionary constraints = new HttpRouteValueDictionary(); if (httpMethods != null) { // Current method constraint implementation is inefficient since it matches before running the constraint. // Consider checking the HTTP method first in a custom route as a performance optimization. constraints["httpMethod"] = new HttpMethodConstraint(httpMethods.AsArray()); } string detokenizedRouteTemplate = InlineRouteTemplateParser.ParseRouteTemplate(routeTemplate, defaults, constraints, ConstraintResolver); return(BuildHttpRoute(detokenizedRouteTemplate, defaults, constraints, actions)); }