public ParametersCollection Match(string virtualPath, ParametersCollection defaultValues)
        {
            IList <string> source = RouteParser.SplitUrlToPathSegmentStrings(virtualPath);

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

            for (int i = 0; i < this.PathSegments.Count; i++)
            {
                PathSegment segment = this.PathSegments[i];
                if (source.Count <= i)
                {
                    flag = true;
                }
                string a = flag ? null : source[i];
                if (segment is SeparatorPathSegment)
                {
                    if (!flag && !string.Equals(a, "/", StringComparison.Ordinal))
                    {
                        return(null);
                    }
                }
                else
                {
                    ContentPathSegment contentPathSegment = segment as ContentPathSegment;
                    if (contentPathSegment != null)
                    {
                        if (contentPathSegment.IsCatchAll)
                        {
                            this.MatchCatchAll(contentPathSegment, source.Skip <string>(i), defaultValues, matchedValues);
                            flag2 = true;
                        }
                        else if (!this.MatchContentPathSegment(contentPathSegment, a, defaultValues, matchedValues))
                        {
                            return(null);
                        }
                    }
                }
            }
            if (!flag2 && (this.PathSegments.Count < source.Count))
            {
                for (int j = this.PathSegments.Count; j < source.Count; j++)
                {
                    if (!RouteParser.IsSeparator(source[j]))
                    {
                        return(null);
                    }
                }
            }
            if (defaultValues != null)
            {
                foreach (var pair in defaultValues)
                {
                    if (!matchedValues.ContainsKey(pair.Key))
                    {
                        matchedValues.Add(pair.Key, pair.Value);
                    }
                }
            }
            return(matchedValues);
        }
        public BoundUrl Bind(ParametersCollection currentValues, ParametersCollection values,
                             ParametersCollection defaultValues, ParametersCollection constraints)
        {
            if (currentValues == null)
            {
                currentValues = new ParametersCollection();
            }
            if (values == null)
            {
                values = new ParametersCollection();
            }
            if (defaultValues == null)
            {
                defaultValues = new ParametersCollection();
            }
            ParametersCollection acceptedValues  = new ParametersCollection();
            List <string>        unusedNewValues = new List <string>(values.Keys);

            ForEachParameter(this.PathSegments, delegate(ParameterSubsegment parameterSubsegment)
            {
                object obj2;
                object obj3;
                string parameterName = parameterSubsegment.ParameterName;
                bool flag            = values.TryGetValue(parameterName, out obj2);
                if (flag)
                {
                    unusedNewValues.Remove(parameterName);
                }
                bool flag22 = currentValues.TryGetValue(parameterName, out obj3);
                if ((flag && flag22) && !RoutePartsEqual(obj3, obj2))
                {
                    return(false);
                }
                if (flag)
                {
                    if (IsRoutePartNonEmpty(obj2))
                    {
                        acceptedValues.Add(parameterName, obj2);
                    }
                }
                else if (flag22)
                {
                    acceptedValues.Add(parameterName, obj3);
                }
                return(true);
            });

            foreach (var pair in values)
            {
                if (IsRoutePartNonEmpty(pair.Value) && !acceptedValues.ContainsKey(pair.Key))
                {
                    acceptedValues.Add(pair.Key, pair.Value);
                }
            }

            foreach (var pair2 in currentValues)
            {
                string str = pair2.Key;
                if (!acceptedValues.ContainsKey(str) && (GetParameterSubsegment(this.PathSegments, str) == null))
                {
                    acceptedValues.Add(str, pair2.Value);
                }
            }

            ForEachParameter(this.PathSegments, delegate(ParameterSubsegment parameterSubsegment)
            {
                object obj2;
                if (!acceptedValues.ContainsKey(parameterSubsegment.ParameterName) &&
                    !IsParameterRequired(parameterSubsegment, defaultValues, out obj2))
                {
                    acceptedValues.Add(parameterSubsegment.ParameterName, obj2);
                }
                return(true);
            });

            if (!ForEachParameter(this.PathSegments, delegate(ParameterSubsegment parameterSubsegment)
            {
                object obj2;
                if (IsParameterRequired(parameterSubsegment, defaultValues, out obj2) &&
                    !acceptedValues.ContainsKey(parameterSubsegment.ParameterName))
                {
                    return(false);
                }
                return(true);
            }))
            {
                return(null);
            }

            ParametersCollection otherDefaultValues = new ParametersCollection(defaultValues);

            ForEachParameter(this.PathSegments, delegate(ParameterSubsegment parameterSubsegment)
            {
                otherDefaultValues.Remove(parameterSubsegment.ParameterName);
                return(true);
            });

            foreach (var pair3 in otherDefaultValues)
            {
                object obj2;
                if (values.TryGetValue(pair3.Key, out obj2))
                {
                    unusedNewValues.Remove(pair3.Key);
                    if (!RoutePartsEqual(obj2, pair3.Value))
                    {
                        return(null);
                    }
                }
            }

            StringBuilder builder  = new StringBuilder();
            StringBuilder builder2 = new StringBuilder();
            bool          flag2    = false;

            for (int i = 0; i < this.PathSegments.Count; i++)
            {
                PathSegment segment = this.PathSegments[i];
                if (segment is SeparatorPathSegment)
                {
                    if (flag2 && (builder2.Length > 0))
                    {
                        builder.Append(builder2.ToString());
                        builder2.Length = 0;
                    }
                    flag2 = false;
                    builder2.Append("/");
                }
                else
                {
                    ContentPathSegment segment2 = segment as ContentPathSegment;
                    if (segment2 != null)
                    {
                        bool flag3 = false;
                        foreach (PathSubsegment subsegment2 in segment2.Subsegments)
                        {
                            LiteralSubsegment subsegment3 = subsegment2 as LiteralSubsegment;
                            if (subsegment3 != null)
                            {
                                flag2 = true;
                                builder2.Append(Uri.EscapeUriString(subsegment3.Literal));
                            }
                            else
                            {
                                ParameterSubsegment subsegment4 = subsegment2 as ParameterSubsegment;
                                if (subsegment4 != null)
                                {
                                    object obj3;
                                    object obj4;
                                    if (flag2 && (builder2.Length > 0))
                                    {
                                        builder.Append(builder2.ToString());
                                        builder2.Length = 0;
                                        flag3           = true;
                                    }
                                    flag2 = false;
                                    if (acceptedValues.TryGetValue(subsegment4.ParameterName, out obj3))
                                    {
                                        unusedNewValues.Remove(subsegment4.ParameterName);
                                    }
                                    defaultValues.TryGetValue(subsegment4.ParameterName, out obj4);
                                    if (RoutePartsEqual(obj3, obj4))
                                    {
                                        builder2.Append(Uri.EscapeUriString(Convert.ToString(obj3, CultureInfo.InvariantCulture)));
                                        continue;
                                    }
                                    if (builder2.Length > 0)
                                    {
                                        builder.Append(builder2.ToString());
                                        builder2.Length = 0;
                                    }
                                    builder.Append(Uri.EscapeUriString(Convert.ToString(obj3, CultureInfo.InvariantCulture)));
                                    flag3 = true;
                                }
                            }
                        }
                        if (flag3 && (builder2.Length > 0))
                        {
                            builder.Append(builder2.ToString());
                            builder2.Length = 0;
                        }
                    }
                }
            }

            if (flag2 && (builder2.Length > 0))
            {
                builder.Append(builder2.ToString());
            }
            if (constraints != null)
            {
                foreach (var pair4 in constraints)
                {
                    unusedNewValues.Remove(pair4.Key);
                }
            }

            if (unusedNewValues.Count > 0)
            {
                bool flag5 = true;
                foreach (string str2 in unusedNewValues)
                {
                    object obj5;
                    if (acceptedValues.TryGetValue(str2, out obj5))
                    {
                        builder.Append(flag5 ? '?'
         : '&');
                        flag5 = false;
                        builder.Append(Uri.EscapeDataString(str2));
                        builder.Append('=');
                        builder.Append(Uri.EscapeDataString(Convert.ToString(obj5, CultureInfo.InvariantCulture)));
                    }
                }
            }

            return(new BoundUrl {
                Url = builder.ToString(), Values = acceptedValues
            });
        }