本文整理汇总了C#中System.Json.JsonObject.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.AddRange方法的具体用法?C# JsonObject.AddRange怎么用?C# JsonObject.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.AddRange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRangeParamsTest
public void AddRangeParamsTest()
{
string key1 = AnyInstance.AnyString;
string key2 = AnyInstance.AnyString2;
JsonValue value1 = AnyInstance.AnyJsonValue1;
JsonValue value2 = AnyInstance.AnyJsonValue2;
List<KeyValuePair<string, JsonValue>> items = new List<KeyValuePair<string, JsonValue>>()
{
new KeyValuePair<string, JsonValue>(key1, value1),
new KeyValuePair<string, JsonValue>(key2, value2),
};
JsonObject target;
target = new JsonObject();
target.AddRange(items[0], items[1]);
Assert.AreEqual(2, target.Count);
ValidateJsonObjectItems(target, key1, value1, key2, value2);
target = new JsonObject();
target.AddRange(items.ToArray());
Assert.AreEqual(2, target.Count);
ValidateJsonObjectItems(target, key1, value1, key2, value2);
ExceptionTestHelper.ExpectException<ArgumentNullException>(delegate { new JsonObject().AddRange((KeyValuePair<string, JsonValue>[])null); });
ExceptionTestHelper.ExpectException<ArgumentNullException>(delegate { new JsonObject().AddRange((IEnumerable<KeyValuePair<string, JsonValue>>)null); });
items[1] = new KeyValuePair<string, JsonValue>(key2, AnyInstance.DefaultJsonValue);
ExceptionTestHelper.ExpectException<ArgumentException>(delegate { new JsonObject().AddRange(items.ToArray()); });
ExceptionTestHelper.ExpectException<ArgumentException>(delegate { new JsonObject().AddRange(items[0], items[1]); });
}
示例2: RemoveKVPTest
public void RemoveKVPTest()
{
JsonObject target = new JsonObject();
KeyValuePair<string, JsonValue> item1 = new KeyValuePair<string, JsonValue>(AnyInstance.AnyString, AnyInstance.AnyJsonValue1);
KeyValuePair<string, JsonValue> item2 = new KeyValuePair<string, JsonValue>(AnyInstance.AnyString2, AnyInstance.AnyJsonValue2);
target.AddRange(item1, item2);
Assert.AreEqual(2, target.Count);
Assert.IsTrue(((ICollection<KeyValuePair<string, JsonValue>>)target).Contains(item1));
Assert.IsTrue(((ICollection<KeyValuePair<string, JsonValue>>)target).Contains(item2));
Assert.IsTrue(((ICollection<KeyValuePair<string, JsonValue>>)target).Remove(item1));
Assert.AreEqual(1, target.Count);
Assert.IsFalse(((ICollection<KeyValuePair<string, JsonValue>>)target).Contains(item1));
Assert.IsTrue(((ICollection<KeyValuePair<string, JsonValue>>)target).Contains(item2));
Assert.IsFalse(((ICollection<KeyValuePair<string, JsonValue>>)target).Remove(item1));
Assert.AreEqual(1, target.Count);
Assert.IsFalse(((ICollection<KeyValuePair<string, JsonValue>>)target).Contains(item1));
Assert.IsTrue(((ICollection<KeyValuePair<string, JsonValue>>)target).Contains(item2));
}