private bool Equals(RoutePatternParameterPart x, RoutePatternParameterPart y) { return (x.Name == y.Name && x.Default == y.Default && x.ParameterKind == y.ParameterKind && Enumerable.SequenceEqual(x.ParameterPolicies, y.ParameterPolicies, this)); }
private bool MatchesConstraints(RoutePattern pattern, RoutePatternParameterPart parameter, string key, RouteValueDictionary requiredValues) { if (pattern.ParameterPolicies.TryGetValue(key, out var policies)) { for (var i = 0; i < policies.Count; i++) { var policy = _policyFactory.Create(parameter, policies[i]); if (policy is IRouteConstraint constraint) { if (!constraint.Match(httpContext: null, NullRouter.Instance, key, requiredValues, RouteDirection.IncomingRequest)) { return(false); } } } } return(true); }
private void RemoveParameterDefault(List <RoutePatternPathSegment> segments, List <RoutePatternParameterPart> parameters, RoutePatternParameterPart parameter) { // We know that a parameter can only appear once, so we only need to rewrite one segment and one parameter. for (var i = 0; i < segments.Count; i++) { var segment = segments[i]; for (var j = 0; j < segment.Parts.Count; j++) { if (object.ReferenceEquals(parameter, segment.Parts[j])) { // Found it! var updatedParameter = RoutePatternFactory.ParameterPart(parameter.Name, @default: null, parameter.ParameterKind, parameter.ParameterPolicies); var updatedParts = new List <RoutePatternPart>(segment.Parts); updatedParts[j] = updatedParameter; segments[i] = RoutePatternFactory.Segment(updatedParts); for (var k = 0; k < parameters.Count; k++) { if (ReferenceEquals(parameter, parameters[k])) { parameters[k] = updatedParameter; break; } } return; } } } }