private static Boolean MatchContentPathSegment(ContentPathSegment routeSegment, String requestPathSegment, IDictionary <String, Object> defaultValues, IDictionary <String, Object> matchedValues) { if (String.IsNullOrEmpty(requestPathSegment)) { if (routeSegment.SubSegments.Count <= 1) { Object segmentValue; var subsegment = routeSegment.SubSegments[0] as ParameterSubSegment; if (subsegment == null) { return(false); } if (defaultValues.TryGetValue(subsegment.ParameterName, out segmentValue)) { matchedValues.Add(subsegment.ParameterName, segmentValue); return(true); } } return(false); } Int32 length = requestPathSegment.Length; Int32 subsegmentIndex = routeSegment.SubSegments.Count - 1; ParameterSubSegment parameterSubSegment = null; while (subsegmentIndex >= 0) { Int32 segmentLength = length; PathSubSegment pathSubSegment = routeSegment.SubSegments[subsegmentIndex]; LiteralSubSegment literalSubSegment = null; if (pathSubSegment is ParameterSubSegment) { parameterSubSegment = pathSubSegment as ParameterSubSegment; } else { literalSubSegment = pathSubSegment as LiteralSubSegment; if (literalSubSegment != null) { Int32 endIndex = requestPathSegment.LastIndexOf(literalSubSegment.Literal, length - 1, StringComparison.OrdinalIgnoreCase); if (endIndex == -1) { return(false); } if ((subsegmentIndex == (routeSegment.SubSegments.Count - 1)) && ((endIndex + literalSubSegment.Literal.Length) != requestPathSegment.Length)) { return(false); } segmentLength = endIndex; } } if ((parameterSubSegment != null) && ((literalSubSegment != null) || (subsegmentIndex == 0))) { Int32 startIndex = 0; Int32 endIndex = length; if (literalSubSegment != null) { startIndex = segmentLength + literalSubSegment.Literal.Length; } String str = requestPathSegment.Substring(startIndex, endIndex - startIndex); if (String.IsNullOrEmpty(str)) { return(false); } matchedValues.Add(parameterSubSegment.ParameterName, str); } length = segmentLength; subsegmentIndex--; } if (length != 0) { return(routeSegment.SubSegments[0] is ParameterSubSegment); } return(true); }
private static Boolean MatchContentPathSegment(ContentPathSegment routeSegment, String requestPathSegment, IDictionary<String, Object> defaultValues, IDictionary<String, Object> matchedValues) { if (String.IsNullOrEmpty(requestPathSegment)) { if (routeSegment.SubSegments.Count <= 1) { Object segmentValue; var subsegment = routeSegment.SubSegments[0] as ParameterSubSegment; if (subsegment == null) { return false; } if (defaultValues.TryGetValue(subsegment.ParameterName, out segmentValue)) { matchedValues.Add(subsegment.ParameterName, segmentValue); return true; } } return false; } Int32 length = requestPathSegment.Length; Int32 subsegmentIndex = routeSegment.SubSegments.Count - 1; ParameterSubSegment parameterSubSegment = null; while (subsegmentIndex >= 0) { Int32 segmentLength = length; PathSubSegment pathSubSegment = routeSegment.SubSegments[subsegmentIndex]; LiteralSubSegment literalSubSegment = null; if (pathSubSegment is ParameterSubSegment) { parameterSubSegment = pathSubSegment as ParameterSubSegment; } else { literalSubSegment = pathSubSegment as LiteralSubSegment; if (literalSubSegment != null) { Int32 endIndex = requestPathSegment.LastIndexOf(literalSubSegment.Literal, length - 1, StringComparison.OrdinalIgnoreCase); if (endIndex == -1) { return false; } if ((subsegmentIndex == (routeSegment.SubSegments.Count - 1)) && ((endIndex + literalSubSegment.Literal.Length) != requestPathSegment.Length)) { return false; } segmentLength = endIndex; } } if ((parameterSubSegment != null) && ((literalSubSegment != null) || (subsegmentIndex == 0))) { Int32 startIndex = 0; Int32 endIndex = length; if (literalSubSegment != null) { startIndex = segmentLength + literalSubSegment.Literal.Length; } String str = requestPathSegment.Substring(startIndex, endIndex-startIndex); if (String.IsNullOrEmpty(str)) { return false; } matchedValues.Add(parameterSubSegment.ParameterName, str); } length = segmentLength; subsegmentIndex--; } if (length != 0) { return (routeSegment.SubSegments[0] is ParameterSubSegment); } return true; }