private MatcherState CreateRoutePatternMatcher(RouteEndpoint endpoint) { var constraints = new Dictionary <string, List <IRouteConstraint> >(StringComparer.OrdinalIgnoreCase); var policies = endpoint.RoutePattern.ParameterPolicies; foreach (var kvp in policies) { var constraintsForParameter = new List <IRouteConstraint>(); var parameter = endpoint.RoutePattern.GetParameter(kvp.Key); for (var i = 0; i < kvp.Value.Count; i++) { var policy = _parameterPolicyFactory.Create(parameter, kvp.Value[i]); if (policy is IRouteConstraint constraint) { constraintsForParameter.Add(constraint); } } if (constraintsForParameter.Count > 0) { constraints.Add(kvp.Key, constraintsForParameter); } } var matcher = new RoutePatternMatcher(endpoint.RoutePattern, new RouteValueDictionary(endpoint.RoutePattern.Defaults)); return(new MatcherState(matcher, constraints)); }
private static void RunTest( string template, string path, RouteValueDictionary defaults, IDictionary <string, object> expected) { // Arrange var matcher = new RoutePatternMatcher( RoutePatternParser.Parse(template), defaults ?? new RouteValueDictionary()); var values = new RouteValueDictionary(); // Act var match = matcher.TryMatch(new PathString(path), values); // Assert if (expected == null) { Assert.False(match); } else { Assert.True(match); Assert.Equal(expected.Count, values.Count); foreach (string key in values.Keys) { Assert.Equal(expected[key], values[key]); } } }
public void Deconstruct(out RoutePatternMatcher matcher, out Dictionary <string, List <IRouteConstraint> > constraints) { matcher = Matcher; constraints = Constraints; }
public MatcherState(RoutePatternMatcher matcher, Dictionary <string, List <IRouteConstraint> > constraints) { Matcher = matcher; Constraints = constraints; }