示例#1
0
        /// <summary>
        /// Parses the specified route into a sequence of nodes.
        /// </summary>
        /// <param name="routeUrl">The route URL to add.</param>
        /// <param name="parameters">The parameters to capture.</param>
        /// <returns>The parsed nodes.</returns>
        public IMatchNode[] Parse(string routeUrl, IEnumerable <ParameterInfo> parameters)
        {
            IReadOnlyDictionary <string, Type> parameterPairs =
                parameters.ToDictionary(p => p.Name, p => p.ParameterType, StringComparer.Ordinal);

            var parser = new NodeParser(this.specializedCaptureNodes);

            parser.ParseUrl(routeUrl, parameterPairs);

            string normalizedUrl = GetNormalizedRoute(routeUrl, parser.Nodes);

            if (!this.normalizedUrls.Add(normalizedUrl))
            {
                throw new InvalidOperationException("The route produces an ambiguous match.");
            }

            return(parser.Nodes.ToArray());
        }