/// <summary> /// Given a path, attempts to match the next part of it to the current segment. /// </summary> /// <param name="route">The route.</param> /// <param name="path">The path.</param> /// <returns> /// An object that indicates whether the path was successfully matched. /// </returns> public override SegmentPathMatch MatchPath(IRoute route, PathIterator path) { var values = new RouteValueDictionary(); var next = path.Next(); if (next.Length == 0) { if (defaultValue != UrlParameter.NotSpecified) { values[parameterName] = defaultValue; } else { return(SegmentPathMatch.Failure(string.Format("The path does not contain a segment for parameter '{0}'", parameterName))); } } else { values[parameterName] = next; if (constraint != null && !constraint.IsValid(route, next, parameterName)) { return(SegmentPathMatch.Failure(string.Format("Segment '{0}' did not match the constraint on parameter '{1}'", next, parameterName))); } } return(SegmentPathMatch.Successful(values)); }
/// <summary> /// Given a path, attempts to match the next part of it to the current segment. /// </summary> /// <param name="route">The route.</param> /// <param name="path">The path.</param> /// <returns> /// An object that indicates whether the path was successfully matched. /// </returns> public override SegmentPathMatch MatchPath(IRoute route, PathIterator path) { var next = path.Next(); return(String.Equals(next, literal, StringComparison.InvariantCultureIgnoreCase) ? SegmentPathMatch.Successful() : SegmentPathMatch.Failure(string.Format("Expected segment '{0}'; got '{1}'", literal, next))); }
/// <summary> /// Matches the path. /// </summary> /// <param name="route">The route.</param> /// <param name="reader">The reader.</param> /// <returns></returns> public override SegmentPathMatch MatchPath(IRoute route, PathIterator reader) { var values = new RouteValueDictionary(); var path = reader.ReadAll(); values[parameterName] = path; if (path.Length == 0) { if (defaultValue != UrlParameter.NotSpecified) { values[parameterName] = defaultValue; } } else if (constraint != null && !constraint.IsValid(route, path, parameterName)) { return(SegmentPathMatch.Failure(string.Format("Segment '{0}' did not match constraint for parameter '{1}'", path, parameterName))); } return(SegmentPathMatch.Successful(values)); }