public MatchingResult IsMatch(string[] pathSegments)
        {
            if (pathSegments.Length != elements.Length)
            {
                return(false);
            }

            var capturedVariables = new List <KeyValuePair <string, object> >();

            for (int i = 0; i < pathSegments.Length; ++i)
            {
                UriTemplateElement templateSegment = elements[i];
                string             pathSegment     = pathSegments[i];
                if (!templateSegment.IsMatch(pathSegment))
                {
                    return(false);
                }

                if (templateSegment.IsVariable)
                {
                    capturedVariables.Add(new KeyValuePair <string, object>(templateSegment.Value, pathSegment));
                }
            }

            return(new MatchingResult(true, capturedVariables));
        }
Ejemplo n.º 2
0
        public MatchingResult IsMatch(string queryString)
        {
            Dictionary <string, string> queryStringPairs = queryString.GetQueryCollection()
                                                           .ToDictionary(p => p.Key, p => p.Value);

            if (!ContainsAllNonVariablePairs(queryStringPairs))
            {
                return(false);
            }

            var variables = new Dictionary <string, object>();

            foreach (KeyValuePair <string, string> pair in queryStringPairs)
            {
                if (!queryElements.ContainsKey(pair.Key))
                {
                    continue;
                }
                UriTemplateElement element = queryElements[pair.Key];
                if (!element.IsMatch(pair.Value))
                {
                    return(false);
                }
                if (element.IsVariable)
                {
                    variables.Add(element.Value, pair.Value);
                }
            }

            return(new MatchingResult(true, variables.Concat(GetNotCapturedVariables(variables))));
        }