diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs index 283de895..39cfd332 100644 --- a/Src/Newtonsoft.Json/Linq/JArray.cs +++ b/Src/Newtonsoft.Json/Linq/JArray.cs @@ -170,7 +170,7 @@ namespace Newtonsoft.Json.Linq { writer.WriteStartArray(); - foreach (JToken token in Children()) + foreach (JToken token in ChildrenTokens) { token.WriteTo(writer, converters); } @@ -293,16 +293,6 @@ namespace Newtonsoft.Json.Linq CopyItemsTo(array, arrayIndex); } - /// - /// Gets the number of elements contained in the . - /// - /// - /// The number of elements contained in the . - public int Count - { - get { return CountItems(); } - } - bool ICollection.IsReadOnly { get { return false; } diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index cdf7a7e5..fd077b84 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -479,7 +479,7 @@ namespace Newtonsoft.Json.Linq throw new ArgumentOutOfRangeException("arrayIndex", "arrayIndex is less than 0."); if (arrayIndex >= array.Length) throw new ArgumentException("arrayIndex is equal to or greater than the length of array."); - if (CountItems() > array.Length - arrayIndex) + if (Count > array.Length - arrayIndex) throw new ArgumentException("The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array."); int index = 0; @@ -490,11 +490,6 @@ namespace Newtonsoft.Json.Linq } } - internal virtual int CountItems() - { - return ChildrenTokens.Count; - } - internal static bool IsTokenUnchanged(JToken currentValue, JToken newValue) { JValue v1 = currentValue as JValue; @@ -784,11 +779,6 @@ namespace Newtonsoft.Json.Linq CopyItemsTo(array, arrayIndex); } - int ICollection.Count - { - get { return CountItems(); } - } - bool ICollection.IsReadOnly { get { return false; } @@ -817,7 +807,7 @@ namespace Newtonsoft.Json.Linq int IList.Add(object value) { Add(EnsureValue(value)); - return CountItems() - 1; + return Count - 1; } void IList.Clear() @@ -875,9 +865,9 @@ namespace Newtonsoft.Json.Linq CopyItemsTo(array, index); } - int ICollection.Count + public int Count { - get { return CountItems(); } + get { return ChildrenTokens.Count; } } bool ICollection.IsSynchronized diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index c4c1adf4..fd81bc99 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -386,6 +386,9 @@ namespace Newtonsoft.Json.Linq bool IDictionary.ContainsKey(string key) { + if (_properties.Dictionary == null) + return false; + return _properties.Dictionary.ContainsKey(key); } @@ -482,7 +485,7 @@ namespace Newtonsoft.Json.Linq /// The number of elements contained in the . public int Count { - get { return Children().Count(); } + get { return ChildrenTokens.Count; } } bool ICollection>.IsReadOnly