/// <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)); }