예제 #1
0
        private static HttpRouteValueDictionary Match(RoutingContext context, HttpRouteValueDictionary defaultValues)
        {
            List <string> pathSegments = context.PathSegments;

            if (defaultValues == null)
            {
                defaultValues = new HttpRouteValueDictionary();
            }
            HttpRouteValueDictionary matchedValues = new HttpRouteValueDictionary();
            bool flag  = false;
            bool flag2 = false;

            for (int i = 0; i < thisPathSegments.Count; i++)
            {
                PathSegment segment = thisPathSegments[i];
                if (pathSegments.Count <= i)
                {
                    flag = true;
                }
                string a = flag ? null : pathSegments[i];
                if (segment is PathSeparatorSegment)
                {
                    if (!flag && !string.Equals(a, "/", StringComparison.Ordinal))
                    {
                        return(null);
                    }
                }
                else
                {
                    PathContentSegment contentPathSegment = segment as PathContentSegment;
                    if (contentPathSegment != null)
                    {
                        if (contentPathSegment.IsCatchAll)
                        {
                            MatchCatchAll(contentPathSegment, pathSegments.Skip <string>(i), defaultValues, matchedValues);
                            flag2 = true;
                        }
                        else if (!MatchContentPathSegment(contentPathSegment, a, defaultValues, matchedValues))
                        {
                            return(null);
                        }
                    }
                }
            }
            if (!flag2 && (this.PathSegments.Count < pathSegments.Count))
            {
                for (int j = thisPathSegments.Count; j < pathSegments.Count; j++)
                {
                    if (!IsSeparator(pathSegments[j]))
                    {
                        return(null);
                    }
                }
            }
            if (defaultValues != null)
            {
                foreach (KeyValuePair <string, object> pair in defaultValues)
                {
                    if (!matchedValues.ContainsKey(pair.Key))
                    {
                        matchedValues.Add(pair.Key, pair.Value);
                    }
                }
            }
            return(matchedValues);
        }