-Changed JObject.ContainsKey to public

This commit is contained in:
James Newton-King
2017-11-26 10:13:13 +13:00
parent f19418f9e3
commit a138852994
3 changed files with 31 additions and 3 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
[![NuGet version (Newtonsoft.Json)](https://img.shields.io/nuget/v/Newtonsoft.Json.svg?style=flat-square)](https://www.nuget.org/packages/Newtonsoft.Json/)
[![Build status](https://ci.appveyor.com/api/projects/status/h1py293didjv3428/branch/master?svg=true)](https://ci.appveyor.com/project/JamesNewtonKing/newtonsoft-json)
- [Homepage](http://www.newtonsoft.com/json)
- [Documentation](http://www.newtonsoft.com/json/help)
- [NuGet Package](https://www.nuget.org/packages/Newtonsoft.Json)
@@ -293,6 +293,27 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(false, contains);
}
[Test]
public void Contains()
{
JObject o = new JObject();
o.Add("PropertyNameValue", new JValue(1));
Assert.AreEqual(1, o.Children().Count());
bool contains = o.ContainsKey("PropertyNameValue");
Assert.AreEqual(true, contains);
contains = o.ContainsKey("does not exist");
Assert.AreEqual(false, contains);
ExceptionAssert.Throws<ArgumentNullException>(() =>
{
contains = o.ContainsKey(null);
Assert.AreEqual(false, contains);
}, @"Value cannot be null.
Parameter name: propertyName");
}
[Test]
public void GenericDictionaryContains()
{
+9 -2
View File
@@ -541,9 +541,16 @@ namespace Newtonsoft.Json.Linq
Add(new JProperty(propertyName, value));
}
bool IDictionary<string, JToken>.ContainsKey(string key)
/// <summary>
/// Determines whether the JSON object has the specified property name.
/// </summary>
/// <param name="propertyName">Name of the property.</param>
/// <returns><c>true</c> if the JSON object has the specified property name; otherwise, <c>false</c>.</returns>
public bool ContainsKey(string propertyName)
{
return _properties.Contains(key);
ValidationUtils.ArgumentNotNull(propertyName, nameof(propertyName));
return _properties.Contains(propertyName);
}
ICollection<string> IDictionary<string, JToken>.Keys => _properties.Keys;