public MatchResult Match(string relativeUri) { var segments = relativeUri.Trim().Split('/', StringSplitOptions.RemoveEmptyEntries).Select(Uri.UnescapeDataString).ToArray(); if (segments.Length == 0) { var indexRoute = Routes.SingleOrDefault(x => x.PageType.FullName != null && x.PageType.FullName.ToLower().EndsWith("index")); if (indexRoute != null) { return(MatchResult.Match(indexRoute)); } } foreach (var route in Routes) { var matchResult = route.Match(segments, relativeUri); if (matchResult.IsMatch) { return(matchResult); } } return(MatchResult.NoMatch()); }
public MatchResult Match(string[] segments) { if (segments.Length != UriSegments.Length) { return(MatchResult.NoMatch()); } for (var i = 0; i < UriSegments.Length; i++) { if (string.Compare(segments[i], UriSegments[i], StringComparison.OrdinalIgnoreCase) != 0) { return(MatchResult.NoMatch()); } } return(MatchResult.Match(this)); }
public MatchResult Match(string[] segments, string relativeUri) { var parameters = ParseQueryString(relativeUri); if (Template.Segments.Length != segments.Length) { return(MatchResult.NoMatch()); } for (var i = 0; i < Template.Segments.Length; i++) { var segment = Template.Segments[i]; var pathSegment = segments[i]; if (!segment.Match(pathSegment, out var matchedParameterValue)) { return(MatchResult.NoMatch()); } else { if (segment.IsParameter) { parameters ??= new Dictionary <string, object>(StringComparer.Ordinal); parameters[segment.Value] = matchedParameterValue; } } } // In addition to extracting parameter values from the URL, each route entry // also knows which other parameters should be supplied with null values. These // are parameters supplied by other route entries matching the same handler. if (UnusedRouteParameterNames.Length > 0) { parameters ??= new Dictionary <string, object>(StringComparer.Ordinal); foreach (var name in UnusedRouteParameterNames) { parameters[name] = null; } } this.Parameters = parameters ?? new Dictionary <string, object>(StringComparer.Ordinal); return(MatchResult.Match(this)); }
public MatchResult Match(string[] segments) { if (segments.Length == 0) { var indexRoute = Routes.SingleOrDefault(x => x.Handler.FullName != null && x.Handler.FullName.ToLower().EndsWith("index")); return(MatchResult.Match(indexRoute)); } foreach (var route in Routes) { var matchResult = route.Match(segments); if (matchResult.IsMatch) { return(matchResult); } } return(MatchResult.NoMatch()); }