public static UriTemplatePathSegment CreateFromUriTemplate(string segment, UriTemplate template)
        {
            // Identifying the type of segment - Literal|Compound|Variable
            switch (UriTemplateHelpers.IdentifyPartType(segment))
            {
            case UriTemplatePartType.Literal:
                return(UriTemplateLiteralPathSegment.CreateFromUriTemplate(segment, template));

            case UriTemplatePartType.Compound:
                return(UriTemplateCompoundPathSegment.CreateFromUriTemplate(segment, template));

            case UriTemplatePartType.Variable:
                if (segment.EndsWith("/", StringComparison.Ordinal))
                {
                    string varName = template.AddPathVariable(UriTemplatePartType.Variable,
                                                              segment.Substring(1, segment.Length - 3));
                    return(new UriTemplateVariablePathSegment(segment, true, varName));
                }
                else
                {
                    string varName = template.AddPathVariable(UriTemplatePartType.Variable,
                                                              segment.Substring(1, segment.Length - 2));
                    return(new UriTemplateVariablePathSegment(segment, false, varName));
                }

            default:
                Fx.Assert("Invalid value from IdentifyStringNature");
                return(null);
            }
        }
        private void AddFinalCompoundSegment(UriTemplateCompoundPathSegment cps, KeyValuePair <UriTemplate, object> kvp)
        {
            if (this.finalCompoundSegment == null)
            {
                this.finalCompoundSegment = new AscendingSortedCompoundSegmentsCollection <UriTemplatePathPartiallyEquivalentSet>();
            }
            UriTemplatePathPartiallyEquivalentSet set = this.finalCompoundSegment.Find(cps);

            if (set == null)
            {
                set = new UriTemplatePathPartiallyEquivalentSet(this.depth + 1);
                this.finalCompoundSegment.Add(cps, set);
            }
            set.Items.Add(kvp);
        }
            public void Add(UriTemplateCompoundPathSegment segment, T value)
            {
                int index = this.items.IndexOfKey(segment);

                if (index == -1)
                {
                    Collection <CollectionItem> subItems = new Collection <CollectionItem>();
                    subItems.Add(new CollectionItem(segment, value));
                    this.items.Add(segment, subItems);
                }
                else
                {
                    Collection <CollectionItem> subItems = this.items.Values[index];
                    subItems.Add(new CollectionItem(segment, value));
                }
            }
        void AddFinalCompoundSegment(UriTemplateCompoundPathSegment cps, KeyValuePair <UriTemplate, object> kvp)
        {
            Fx.Assert(cps != null, "must be - based on the segment nature");
            if (this.finalCompoundSegment == null)
            {
                this.finalCompoundSegment = new AscendingSortedCompoundSegmentsCollection <UriTemplatePathPartiallyEquivalentSet>();
            }
            UriTemplatePathPartiallyEquivalentSet pes = this.finalCompoundSegment.Find(cps);

            if (pes == null)
            {
                pes = new UriTemplatePathPartiallyEquivalentSet(this.depth + 1);
                this.finalCompoundSegment.Add(cps, pes);
            }
            pes.Items.Add(kvp);
        }
            public void Add(UriTemplateCompoundPathSegment segment, T value)
            {
                int num = this.items.IndexOfKey(segment);

                if (num == -1)
                {
                    Collection <CollectionItem <T> > collection = new Collection <CollectionItem <T> > {
                        new CollectionItem <T>(segment, value)
                    };
                    this.items.Add(segment, collection);
                }
                else
                {
                    this.items.Values[num].Add(new CollectionItem <T>(segment, value));
                }
            }
        UriTemplateTrieNode AddNextCompoundSegment(UriTemplateCompoundPathSegment cps)
        {
            Fx.Assert(cps != null, "must be - based on the segment nature");
            if (this.nextCompoundSegment == null)
            {
                this.nextCompoundSegment = new AscendingSortedCompoundSegmentsCollection <UriTemplateTrieLocation>();
            }
            UriTemplateTrieLocation nextLocation = this.nextCompoundSegment.Find(cps);

            if (nextLocation == null)
            {
                UriTemplateTrieNode nextNode = new UriTemplateTrieNode(this.depth + 1);
                nextNode.onFailure = new UriTemplateTrieLocation(this, UriTemplateTrieIntraNodeLocation.AfterCompound);
                nextLocation       = new UriTemplateTrieLocation(nextNode, UriTemplateTrieIntraNodeLocation.BeforeLiteral);
                this.nextCompoundSegment.Add(cps, nextLocation);
            }
            return(nextLocation.node);
        }
            public T Find(UriTemplateCompoundPathSegment segment)
            {
                int index = this.items.IndexOfKey(segment);

                if (index == -1)
                {
                    return(null);
                }
                Collection <CollectionItem> subItems = this.items.Values[index];

                for (int i = 0; i < subItems.Count; i++)
                {
                    if (subItems[i].Segment.IsEquivalentTo(segment, false))
                    {
                        return(subItems[i].Value);
                    }
                }
                return(null);
            }
        public static UriTemplatePathSegment CreateFromUriTemplate(string segment, UriTemplate template)
        {
            switch (UriTemplateHelpers.IdentifyPartType(segment))
            {
            case UriTemplatePartType.Literal:
                return(UriTemplateLiteralPathSegment.CreateFromUriTemplate(segment, template));

            case UriTemplatePartType.Compound:
                return(UriTemplateCompoundPathSegment.CreateFromUriTemplate(segment, template));

            case UriTemplatePartType.Variable:
                if (!segment.EndsWith("/", StringComparison.Ordinal))
                {
                    return(new UriTemplateVariablePathSegment(segment, false, template.AddPathVariable(UriTemplatePartType.Variable, segment.Substring(1, segment.Length - 2))));
                }
                return(new UriTemplateVariablePathSegment(segment, true, template.AddPathVariable(UriTemplatePartType.Variable, segment.Substring(1, segment.Length - 3))));
            }
            return(null);
        }
            public T Find(UriTemplateCompoundPathSegment segment)
            {
                int num = this.items.IndexOfKey(segment);

                if (num != -1)
                {
                    Collection <CollectionItem <T> > collection = this.items.Values[num];
                    for (int i = 0; i < collection.Count; i++)
                    {
                        CollectionItem <T> item = collection[i];
                        if (item.Segment.IsEquivalentTo(segment, false))
                        {
                            CollectionItem <T> item2 = collection[i];
                            return(item2.Value);
                        }
                    }
                }
                return(default(T));
            }
        private UriTemplateTrieNode AddNextCompoundSegment(UriTemplateCompoundPathSegment cps)
        {
            if (this.nextCompoundSegment == null)
            {
                this.nextCompoundSegment = new AscendingSortedCompoundSegmentsCollection <UriTemplateTrieLocation>();
            }
            UriTemplateTrieLocation location = this.nextCompoundSegment.Find(cps);

            if (location == null)
            {
                UriTemplateTrieNode n = new UriTemplateTrieNode(this.depth + 1)
                {
                    onFailure = new UriTemplateTrieLocation(this, UriTemplateTrieIntraNodeLocation.AfterCompound)
                };
                location = new UriTemplateTrieLocation(n, UriTemplateTrieIntraNodeLocation.BeforeLiteral);
                this.nextCompoundSegment.Add(cps, location);
            }
            return(location.node);
        }
 public CollectionItem(UriTemplateCompoundPathSegment segment, T value)
 {
     this.segment = segment;
     this.value   = value;
 }