-Changed JObject.ContainsKey to public
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[](https://www.nuget.org/packages/Newtonsoft.Json/)
|
[](https://www.nuget.org/packages/Newtonsoft.Json/)
|
||||||
[](https://ci.appveyor.com/project/JamesNewtonKing/newtonsoft-json)
|
[](https://ci.appveyor.com/project/JamesNewtonKing/newtonsoft-json)
|
||||||
|
|
||||||
- [Homepage](http://www.newtonsoft.com/json)
|
- [Homepage](http://www.newtonsoft.com/json)
|
||||||
- [Documentation](http://www.newtonsoft.com/json/help)
|
- [Documentation](http://www.newtonsoft.com/json/help)
|
||||||
- [NuGet Package](https://www.nuget.org/packages/Newtonsoft.Json)
|
- [NuGet Package](https://www.nuget.org/packages/Newtonsoft.Json)
|
||||||
|
|||||||
@@ -293,6 +293,27 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
Assert.AreEqual(false, contains);
|
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]
|
[Test]
|
||||||
public void GenericDictionaryContains()
|
public void GenericDictionaryContains()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -541,9 +541,16 @@ namespace Newtonsoft.Json.Linq
|
|||||||
Add(new JProperty(propertyName, value));
|
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;
|
ICollection<string> IDictionary<string, JToken>.Keys => _properties.Keys;
|
||||||
|
|||||||
Reference in New Issue
Block a user