Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/Newtonsoft.Json.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamesNK <james@newtonking.com>2011-05-28 05:49:26 +0400
committerJamesNK <james@newtonking.com>2011-05-28 05:49:26 +0400
commit3997b601ffba23f71368c625eb930fba5e82e65c (patch)
tree7ffc8481b18cec90b1815fe7f4f0540f88899b8d
parent203f79ae9c14cd7bdcfece5416967db01ef5346d (diff)
-Added Count to JContainer
-Minor fixes and improvements
-rw-r--r--Src/Newtonsoft.Json/Linq/JArray.cs12
-rw-r--r--Src/Newtonsoft.Json/Linq/JContainer.cs18
-rw-r--r--Src/Newtonsoft.Json/Linq/JObject.cs5
3 files changed, 9 insertions, 26 deletions
diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs
index 283de89..39cfd33 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);
}
- /// <summary>
- /// Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.
- /// </summary>
- /// <value></value>
- /// <returns>The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</returns>
- public int Count
- {
- get { return CountItems(); }
- }
-
bool ICollection<JToken>.IsReadOnly
{
get { return false; }
diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs
index cdf7a7e..fd077b8 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<JToken>.Count
- {
- get { return CountItems(); }
- }
-
bool ICollection<JToken>.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 c4c1adf..fd81bc9 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<string, JToken>.ContainsKey(string key)
{
+ if (_properties.Dictionary == null)
+ return false;
+
return _properties.Dictionary.ContainsKey(key);
}
@@ -482,7 +485,7 @@ namespace Newtonsoft.Json.Linq
/// <returns>The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</returns>
public int Count
{
- get { return Children().Count(); }
+ get { return ChildrenTokens.Count; }
}
bool ICollection<KeyValuePair<string,JToken>>.IsReadOnly