3 using System.Collections;
4 using System.Collections.Generic;
5 using System.Globalization;
11 public class JsonArray : JsonValue, IList<JsonValue>
15 IEnumerable<JsonValue> source;
17 public JsonArray (params JsonValue [] items)
18 : this ((IEnumerable<JsonValue>) items)
22 public JsonArray (IEnumerable<JsonValue> items)
25 throw new ArgumentNullException ("items");
29 public override int Count {
31 if (known_count < 0) {
33 known_count = list.Count;
36 foreach (JsonValue v in source)
44 public bool IsReadOnly {
48 public override sealed JsonValue this [int index] {
53 foreach (JsonValue v in source)
56 throw new ArgumentOutOfRangeException ("index");
64 public override JsonType JsonType {
65 get { return JsonType.Array; }
68 public void Add (JsonValue item)
71 throw new ArgumentNullException ("item");
76 public void AddRange (IEnumerable<JsonValue> items)
79 throw new ArgumentNullException ("items");
81 list.AddRange (items);
83 source = new MergedEnumerable<JsonValue> (source, items);
86 public void AddRange (JsonValue [] items)
88 AddRange ((IEnumerable<JsonValue>) items);
91 static readonly JsonValue [] empty = new JsonValue [0];
101 public bool Contains (JsonValue item)
104 throw new ArgumentNullException ("item");
105 foreach (JsonValue v in this)
111 public void CopyTo (JsonValue [] array, int arrayIndex)
114 list.CopyTo (array, arrayIndex);
116 foreach (JsonValue v in source)
117 array [arrayIndex++] = v;
120 public int IndexOf (JsonValue item)
123 throw new ArgumentNullException ("item");
125 foreach (JsonValue v in this) {
133 public void Insert (int index, JsonValue item)
136 list.Insert (index, item);
139 public bool Remove (JsonValue item)
142 return list.Remove (item);
145 public void RemoveAt (int index)
148 list.RemoveAt (index);
151 public override void Save (Stream stream)
154 throw new ArgumentNullException ("stream");
155 stream.WriteByte ((byte) '[');
156 for (int i = 0; i < Count; i++) {
157 this [i].Save (stream);
159 stream.WriteByte ((byte) ',');
160 stream.WriteByte ((byte) ' ');
163 stream.WriteByte ((byte) ']');
169 list = new List<JsonValue> (source);
174 IEnumerator<JsonValue> IEnumerable<JsonValue>.GetEnumerator ()
176 return source.GetEnumerator ();
179 IEnumerator IEnumerable.GetEnumerator ()
181 return source.GetEnumerator ();