public void TestHasProperty() { var obj = JsonConverter.ToMap( "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 }, \"value3\": [ 444, { \"value311\": 555 } ] }" ); var has = RecursiveObjectReader.HasProperty(obj, ""); Assert.False(has); has = RecursiveObjectReader.HasProperty(obj, "value1"); Assert.True(has); has = RecursiveObjectReader.HasProperty(obj, "value2"); Assert.True(has); has = RecursiveObjectReader.HasProperty(obj, "value2.value21"); Assert.True(has); has = RecursiveObjectReader.HasProperty(obj, "value2.value31"); Assert.False(has); has = RecursiveObjectReader.HasProperty(obj, "value2.value21.value211"); Assert.False(has); has = RecursiveObjectReader.HasProperty(obj, "valueA.valueB.valueC"); Assert.False(has); has = RecursiveObjectReader.HasProperty(obj, "value3"); Assert.True(has); has = RecursiveObjectReader.HasProperty(obj, "value3.0"); Assert.True(has); has = RecursiveObjectReader.HasProperty(obj, "value3.0.value311"); Assert.False(has); has = RecursiveObjectReader.HasProperty(obj, "value3.1"); Assert.True(has); has = RecursiveObjectReader.HasProperty(obj, "value3.1.value311"); Assert.True(has); has = RecursiveObjectReader.HasProperty(obj, "value3.2"); Assert.False(has); }
/// <summary> /// Checks if this map contains an element with specified key. /// /// The key can be defined using dot notation and allows to recursively access /// elements of elements. /// </summary> /// <param name="key">a key to be checked</param> /// <returns>true if this map contains the key or false otherwise.</returns> public new bool ContainsKey(string key) { return(RecursiveObjectReader.HasProperty(this, key)); }