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


C# ParameterList.Remove方法代码示例

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


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

示例1: TestArgumentExceptions

		public void TestArgumentExceptions ()
		{
			const string invalid = "X-测试文本";
			var list = new ParameterList ();
			Parameter param;
			string value;

			// Add
			Assert.Throws<ArgumentNullException> (() => list.Add ((Encoding) null, "name", "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add (Encoding.UTF8, null, "value"));
			Assert.Throws<ArgumentException> (() => list.Add (Encoding.UTF8, string.Empty, "value"));
			Assert.Throws<ArgumentException> (() => list.Add (Encoding.UTF8, invalid, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add (Encoding.UTF8, "name", null));
			Assert.Throws<ArgumentNullException> (() => list.Add ((string) null, "name", "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add ("utf-8", null, "value"));
			Assert.Throws<ArgumentException> (() => list.Add ("utf-8", string.Empty, "value"));
			Assert.Throws<ArgumentException> (() => list.Add ("utf-8", invalid, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add ("utf-8", "name", null));
			Assert.Throws<ArgumentNullException> (() => list.Add (null, "value"));
			Assert.Throws<ArgumentException> (() => list.Add (string.Empty, "value"));
			Assert.Throws<ArgumentException> (() => list.Add (invalid, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Add ("name", null));
			Assert.Throws<ArgumentNullException> (() => list.Add (null));

			// Contains
			Assert.Throws<ArgumentNullException> (() => list.Contains ((Parameter) null));
			Assert.Throws<ArgumentNullException> (() => list.Contains ((string) null));

			// CopyTo
			Assert.Throws<ArgumentOutOfRangeException> (() => list.CopyTo (new Parameter[0], -1));
			Assert.Throws<ArgumentNullException> (() => list.CopyTo (null, 0));

			// IndexOf
			Assert.Throws<ArgumentNullException> (() => list.IndexOf ((Parameter) null));
			Assert.Throws<ArgumentNullException> (() => list.IndexOf ((string) null));

			// Insert
			list.Add ("name", "value");
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, new Parameter ("name", "value")));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, "field", "value"));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, null, "value"));
			Assert.Throws<ArgumentException> (() => list.Insert (0, string.Empty, "value"));
			Assert.Throws<ArgumentException> (() => list.Insert (0, invalid, "value"));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, "name", null));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, null));

			// Remove
			Assert.Throws<ArgumentNullException> (() => list.Remove ((Parameter) null));
			Assert.Throws<ArgumentNullException> (() => list.Remove ((string) null));

			// RemoveAt
			Assert.Throws<ArgumentOutOfRangeException> (() => list.RemoveAt (-1));

			// TryGetValue
			Assert.Throws<ArgumentNullException> (() => list.TryGetValue (null, out param));
			Assert.Throws<ArgumentNullException> (() => list.TryGetValue (null, out value));

			// Indexers
			Assert.Throws<ArgumentOutOfRangeException> (() => list[-1] = new Parameter ("name", "value"));
			Assert.Throws<ArgumentOutOfRangeException> (() => param = list[-1]);
			Assert.Throws<ArgumentNullException> (() => list[0] = null);
			Assert.Throws<ArgumentNullException> (() => list[null] = "value");
			Assert.Throws<ArgumentNullException> (() => value = list[null]);
			Assert.Throws<ArgumentNullException> (() => list["name"] = null);
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:65,代码来源:ParameterListTests.cs

示例2: TestBasicFunctionality

		public void TestBasicFunctionality ()
		{
			var list = new ParameterList ();
			Parameter parameter;
			string value;
			int index;

			Assert.IsFalse (list.IsReadOnly, "IsReadOnly");
			Assert.AreEqual (0, list.Count);

			list.Add (new Parameter ("abc", "0"));
			list.Add (Encoding.UTF8, "def", "1");
			list.Add ("ghi", "2");

			Assert.AreEqual (3, list.Count, "Count");
			Assert.IsTrue (list.Contains (list[0]));
			Assert.IsTrue (list.Contains ("aBc"));
			Assert.IsTrue (list.Contains ("DEf"));
			Assert.IsTrue (list.Contains ("gHI"));
			Assert.AreEqual (0, list.IndexOf ("aBc"));
			Assert.AreEqual (1, list.IndexOf ("dEF"));
			Assert.AreEqual (2, list.IndexOf ("Ghi"));
			Assert.AreEqual ("abc", list[0].Name);
			Assert.AreEqual ("def", list[1].Name);
			Assert.AreEqual ("ghi", list[2].Name);
			Assert.AreEqual ("0", list["AbC"]);
			Assert.AreEqual ("1", list["dEf"]);
			Assert.AreEqual ("2", list["GHi"]);

			Assert.IsTrue (list.TryGetValue ("Abc", out parameter));
			Assert.AreEqual ("abc", parameter.Name);
			Assert.IsTrue (list.TryGetValue ("Abc", out value));
			Assert.AreEqual ("0", value);

			Assert.IsFalse (list.Remove ("xyz"), "Remove");
			list.Insert (0, new Parameter ("xyz", "3"));
			Assert.IsTrue (list.Remove ("xyz"), "Remove");

			var array = new Parameter[list.Count];
			list.CopyTo (array, 0);
			Assert.AreEqual ("abc", array[0].Name);
			Assert.AreEqual ("def", array[1].Name);
			Assert.AreEqual ("ghi", array[2].Name);

			index = 0;
			foreach (var param in list) {
				Assert.AreEqual (array[index], param);
				index++;
			}

			list.Clear ();
			Assert.AreEqual (0, list.Count, "Clear");

			list.Add ("xyz", "3");
			list.Insert (0, array[2]);
			list.Insert (0, array[1].Name, array[1].Value);
			list.Insert (0, array[0]);

			Assert.AreEqual (4, list.Count);
			Assert.AreEqual ("abc", list[0].Name);
			Assert.AreEqual ("def", list[1].Name);
			Assert.AreEqual ("ghi", list[2].Name);
			Assert.AreEqual ("xyz", list[3].Name);
			Assert.AreEqual ("0", list["AbC"]);
			Assert.AreEqual ("1", list["dEf"]);
			Assert.AreEqual ("2", list["GHi"]);
			Assert.AreEqual ("3", list["XYZ"]);

			list.RemoveAt (3);
			Assert.AreEqual (3, list.Count);

			Assert.AreEqual ("; abc=\"0\"; def=\"1\"; ghi=\"2\"", list.ToString ());
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:73,代码来源:ParameterListTests.cs


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