コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
            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));
                }
            }
コード例 #4
0
        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);
        }
コード例 #5
0
            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));
                }
            }
コード例 #6
0
        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);
        }
コード例 #7
0
            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);
            }
コード例 #8
0
        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);
        }
コード例 #9
0
            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));
            }
コード例 #10
0
        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);
        }
コード例 #11
0
 public CollectionItem(UriTemplateCompoundPathSegment segment, T value)
 {
     this.segment = segment;
     this.value   = value;
 }