-Added Count to JContainer

-Minor fixes and improvements
This commit is contained in:
JamesNK
2011-05-28 01:49:26 +00:00
parent 203f79ae9c
commit 3997b601ff
3 changed files with 9 additions and 26 deletions
+1 -11
View File
@@ -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; }
+4 -14
View File
@@ -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
+4 -1
View File
@@ -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