当前位置: 首页>>代码示例>>C#>>正文


C# OrderedDictionary.Insert方法代码示例

本文整理汇总了C#中System.Collections.Specialized.OrderedDictionary.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedDictionary.Insert方法的具体用法?C# OrderedDictionary.Insert怎么用?C# OrderedDictionary.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Specialized.OrderedDictionary的用法示例。


在下文中一共展示了OrderedDictionary.Insert方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Common

		private void Common (OrderedDictionary od)
		{
			Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
			Assert.AreEqual (0, od.Count, "Count-0");
			Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
			od.Add ("a", "1");
			Assert.AreEqual (1, od.Count, "Count-1");
			od["a"] = "11";
			Assert.AreEqual ("11", od["a"], "this[string]");
			od[0] = "111";
			Assert.AreEqual ("111", od[0], "this[int]");

			DictionaryEntry[] array = new DictionaryEntry[2];
			od.CopyTo (array, 1);

			Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
			Assert.AreEqual (1, od.Keys.Count, "Keys");
			Assert.AreEqual (1, od.Values.Count, "Values");
			Assert.IsTrue (od.Contains ("a"), "Contains(a)");
			Assert.IsFalse (od.Contains ("111"), "Contains(111)");

			od.Insert (0, "b", "2");
			Assert.AreEqual (2, od.Count, "Count-2");
			od.Add ("c", "3");
			Assert.AreEqual (3, od.Count, "Count-3");

			OrderedDictionary ro = od.AsReadOnly ();

			od.RemoveAt (2);
			Assert.AreEqual (2, od.Count, "Count-4");
			Assert.IsFalse (od.Contains ("c"), "Contains(c)");

			od.Remove ("b");
			Assert.AreEqual (1, od.Count, "Count-5");
			Assert.IsFalse (od.Contains ("b"), "Contains(b)");

			od.Clear ();
			Assert.AreEqual (0, od.Count, "Count-6");

			Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
			// it's a read-only reference
			Assert.AreEqual (0, od.Count, "Count-7");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:43,代码来源:OrderedDictionaryTest.cs

示例2: BuildPortalAliasesRegexDictionary

        private static OrderedDictionary BuildPortalAliasesRegexDictionary()
        {
            IDictionary<string, PortalAliasInfo> aliases = TestablePortalAliasController.Instance.GetPortalAliases();
            //create a new OrderedDictionary.  We use this because we
            //want to key by the correct regex pattern and return the
            //portalAlias that matches, and we want to preserve the
            //order of the items, such that the item with the most path separators (/)
            //is at the front of the list.  
            var regexList = new OrderedDictionary(aliases.Count);
            //this regex pattern, when formatted with the httpAlias, will match a request 
            //for this portalAlias
            const string aliasRegexPattern = @"(?:^(?<http>http[s]{0,1}://){0,1})(?:(?<alias>_ALIAS_)(?<path>$|\?[\w]*|/[\w]*))";
            var pathLengths = new List<int>();
            foreach (string aliasKey in aliases.Keys)
            {
                PortalAliasInfo alias = aliases[aliasKey];
                //regex escape the portal alias for inclusion into a regex pattern
                string plainAlias = alias.HTTPAlias;
                string escapedAlias = Regex.Escape(plainAlias);
                var aliasesToAdd = new List<string> { escapedAlias };
                //check for existence of www. version of domain, if it doesn't have a www.
                if (plainAlias.ToLower().StartsWith("www."))
                {
                    if (plainAlias.Length > 4)
                    {
                        string noWWWVersion = plainAlias.Substring(4);
                        if (!aliases.ContainsKey(noWWWVersion))
                        {
                            //there is no no-www version of the alias
                            aliasesToAdd.Add(Regex.Escape(noWWWVersion));
                        }
                    }
                }
                else
                {
                    string wwwVersion = "www." + plainAlias;
                    if (!aliases.ContainsKey(wwwVersion))
                    {
                        aliasesToAdd.Add(Regex.Escape(wwwVersion));
                    }
                }
                int count = 0;
                foreach (string aliasToAdd in aliasesToAdd)
                {
                    //set flag on object to know whether to redirect or not
                    count++;
                    var aliasObject = new PortalAliasInfo(alias) { Redirect = count != 1 };

                    //format up the regex pattern by replacing the alias portion with the portal alias name
                    string regexPattern = aliasRegexPattern.Replace("_ALIAS_", aliasToAdd);
                    //work out how many path separators there are in the portalAlias (ie myalias/mychild = 1 path)
                    int pathLength = plainAlias.Split('/').GetUpperBound(0);
                    //now work out where in the list we should put this portalAlias regex pattern
                    //the list is to be sorted so that those aliases with the most paths 
                    //are at the front of the list : ie, they are tested first
                    int insertPoint = pathLengths.Count - 1;
                    //walk through the existing list of path lengths,
                    //and ascertain where in the list this one falls
                    //if they are all the same path length, then place them in portal alias order
                    for (int i = 0; i < pathLengths.Count; i++)
                    {
                        insertPoint = i;
                        if (pathLength > pathLengths[i])
                        {
                            //larger than this position, insert at this value
                            break;
                        }
                        insertPoint++; //next one along (if at end, means add)
                    }
                    if (pathLengths.Count > 0 && insertPoint <= pathLengths.Count - 1)
                    {
                        //put the new regex pattern into the correct position
                        regexList.Insert(insertPoint, regexPattern, aliasObject);
                        pathLengths.Insert(insertPoint, pathLength);
                    }
                    else
                    {
                        //put the new regex pattern on the end of the list
                        regexList.Add(regexPattern, aliasObject);
                        pathLengths.Add(pathLength);
                    }
                }
            }
            return regexList;
        }
开发者ID:vsnobbert,项目名称:Dnn.Platform,代码行数:85,代码来源:TabIndexController.cs

示例3: InsertTests

        public void InsertTests()
        {
            var d = new OrderedDictionary();
            Assert.Throws<ArgumentOutOfRangeException>(() => d.Insert(-1, "foo", "bar"));
            Assert.Throws<ArgumentNullException>(() => d.Insert(0, null, "bar"));
            Assert.Throws<ArgumentOutOfRangeException>(() => d.Insert(1, "foo", "bar"));

            d.Insert(0, "foo", "bar");
            Assert.Equal("bar", d["foo"]);
            Assert.Equal("bar", d[0]);
            Assert.Throws<ArgumentException>(() => d.Insert(0, "foo", "bar"));

            d.Insert(0, "aaa", "bbb");
            Assert.Equal("bbb", d["aaa"]);
            Assert.Equal("bbb", d[0]);

            d.Insert(0, "zzz", "ccc");
            Assert.Equal("ccc", d["zzz"]);
            Assert.Equal("ccc", d[0]);

            d.Insert(3, "13", "37");
            Assert.Equal("37", d["13"]);
            Assert.Equal("37", d[3]);
        }
开发者ID:rajeevkb,项目名称:corefx,代码行数:24,代码来源:OrderedDictionaryTests.cs

示例4: ReadOnly_Insert

		public void ReadOnly_Insert ()
		{
			OrderedDictionary od = new OrderedDictionary ().AsReadOnly ();
			od.Insert (0, "a", "1");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:5,代码来源:OrderedDictionaryTest.cs

示例5: AsReadOnly_AttemptingToModifyDictionary_Throws

        public void AsReadOnly_AttemptingToModifyDictionary_Throws()
        {
            OrderedDictionary orderedDictionary = new OrderedDictionary().AsReadOnly();
            Assert.Throws<NotSupportedException>(() => orderedDictionary[0] = "value");
            Assert.Throws<NotSupportedException>(() => orderedDictionary["key"] = "value");
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Add("key", "value"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Insert(0, "key", "value"));
 
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Remove("key"));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.RemoveAt(0));
            Assert.Throws<NotSupportedException>(() => orderedDictionary.Clear());
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:13,代码来源:OrderedDictionaryTests.cs


注:本文中的System.Collections.Specialized.OrderedDictionary.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。