public bool Match(string part, string value, int index, MatchData matchData) { if (!OnMatch(part, matchData)) { return false; } if (index == -1) { if (_typeInfos == null) return false; matchData.Add(_typeInfos); return true; } int nextIndex = value.IndexOf('/', ++index); part = nextIndex == -1 ? value.Substring(index) : value.Substring(index, nextIndex - index); IMatcher matcher; if (_statics.TryGetValue(part, out matcher)) { return matcher.Match(part, value, nextIndex, matchData); } bool found = false; foreach (var t in _matchers) { found = t.Match(part, value, nextIndex, matchData) || found; } return found; }
/// <summary> /// Gets the type of handler for the specified URL. /// </summary> /// <param name="url">The URL.</param> /// <param name="variables">The variables.</param> /// <param name="contentType">Value of the Content-Type header from the Request.</param> /// <param name="acceptTypes">Values of the Accepts header from the Request.</param> /// <returns></returns> public Type Get(string url, out IDictionary<string, string> variables, string contentType = null, IList<string> acceptTypes = null) { variables = null; url = url.Trim('/'); int nextIndex = url.IndexOf('/'); string part = nextIndex >= 0 ? url.Substring(0, nextIndex) : url; IMatcher matcher; var matchData = new MatchData(); bool found = false; if (_statics.TryGetValue(part, out matcher)) { found = matcher.Match(part, url, nextIndex, matchData); } if (!found) { found = _matchers.Aggregate(false, (current, t) => t.Match(part, url, nextIndex, matchData) || current); } if (!found) return null; variables = matchData.Variables; if (matchData.Single != null) { return matchData.Single.HandlerType; } return matchData.ResolveByMediaTypes(contentType, acceptTypes); }
protected override bool OnMatch(string part, MatchData matchData) { matchData.SetVariable(_trimmed, part); return true; }
protected override bool OnMatch(string value, MatchData matchData) { return value.Equals(Pattern, StringComparison.OrdinalIgnoreCase); }
protected abstract bool OnMatch(string part, MatchData matchData);
protected override bool OnMatch(string part, MatchData matchData) { matchData.SetVariable(_trimmed, part); return(true); }