Ejemplo n.º 1
0
        public TemplateRoute(
            IRouter target,
            string routeName,
            string routeTemplate,
            IDictionary<string, object> defaults,
            IDictionary<string, object> constraints,
            IDictionary<string, object> dataTokens,
            IInlineConstraintResolver inlineConstraintResolver)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            _target = target;
            _routeTemplate = routeTemplate ?? string.Empty;
            Name = routeName;

            _dataTokens = dataTokens == null ? RouteValueDictionary.Empty : new RouteValueDictionary(dataTokens);

            // Data we parse from the template will be used to fill in the rest of the constraints or
            // defaults. The parser will throw for invalid routes.
            _parsedTemplate = TemplateParser.Parse(RouteTemplate);

            _constraints = GetConstraints(inlineConstraintResolver, RouteTemplate, _parsedTemplate, constraints);
            _defaults = GetDefaults(_parsedTemplate, defaults);

            _matcher = new TemplateMatcher(_parsedTemplate, Defaults);
            _binder = new TemplateBinder(_parsedTemplate, Defaults);
        }
Ejemplo n.º 2
0
        public TemplateRoute(
            IRouter target,
            string routeName,
            string routeTemplate,
            IDictionary <string, object> defaults,
            IDictionary <string, object> constraints,
            IDictionary <string, object> dataTokens,
            IInlineConstraintResolver inlineConstraintResolver)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            _target        = target;
            _routeTemplate = routeTemplate ?? string.Empty;
            Name           = routeName;

            _dataTokens = dataTokens == null ? RouteValueDictionary.Empty : new RouteValueDictionary(dataTokens);

            // Data we parse from the template will be used to fill in the rest of the constraints or
            // defaults. The parser will throw for invalid routes.
            _parsedTemplate = TemplateParser.Parse(RouteTemplate);

            _constraints = GetConstraints(inlineConstraintResolver, RouteTemplate, _parsedTemplate, constraints);
            _defaults    = GetDefaults(_parsedTemplate, defaults);

            _matcher = new TemplateMatcher(_parsedTemplate, Defaults);
            _binder  = new TemplateBinder(_parsedTemplate, Defaults);
        }
Ejemplo n.º 3
0
        public TemplateRoute([NotNull] IRouter target,
                             string routeName,
                             string routeTemplate,
                             IDictionary <string, object> defaults,
                             IDictionary <string, object> constraints,
                             IDictionary <string, object> dataTokens,
                             IInlineConstraintResolver inlineConstraintResolver)
        {
            _target        = target;
            _routeTemplate = routeTemplate ?? string.Empty;
            Name           = routeName;
            _defaults      = defaults ?? new RouteValueDictionary();
            _constraints   = RouteConstraintBuilder.BuildConstraints(constraints, _routeTemplate) ??
                             new Dictionary <string, IRouteConstraint>();
            _dataTokens = dataTokens ?? new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            // The parser will throw for invalid routes.
            _parsedTemplate = TemplateParser.Parse(RouteTemplate, inlineConstraintResolver);
            UpdateInlineDefaultValuesAndConstraints();

            _matcher = new TemplateMatcher(_parsedTemplate);
            _binder  = new TemplateBinder(_parsedTemplate, _defaults);
        }
Ejemplo n.º 4
0
 private void EnsureBinder(HttpContext context)
 {
     if (_binder == null)
     {
         var urlEncoder = context.RequestServices.GetRequiredService<UrlEncoder>();
         var pool = context.RequestServices.GetRequiredService<ObjectPool<UriBuildingContext>>();
         _binder = new TemplateBinder(urlEncoder, pool, ParsedTemplate, Defaults);
     }
 }