Remove invalid tests for image palettes in GdiPlusTest (#5671)
[mono.git] / mcs / class / System.Json / System.Json / JsonArray.cs
1
2 using System;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.Globalization;
6 using System.IO;
7 using System.Text;
8
9 namespace System.Json
10 {
11         public class JsonArray : JsonValue, IList<JsonValue>
12         {
13                 List<JsonValue> list;
14
15                 public JsonArray (params JsonValue [] items)
16                 {
17                         list = new List<JsonValue> ();
18                         AddRange (items);
19                 }
20
21                 public JsonArray (IEnumerable<JsonValue> items)
22                 {
23                         if (items == null)
24                                 throw new ArgumentNullException ("items");
25
26                         list = new List<JsonValue> (items);
27                 }
28
29                 public override int Count {
30                         get { return list.Count; }
31                 }
32
33                 public bool IsReadOnly {
34                         get { return false; }
35                 }
36
37                 public override sealed JsonValue this [int index] {
38                         get { return list [index]; }
39                         set { list [index] = value; }
40                 }
41
42                 public override JsonType JsonType {
43                         get { return JsonType.Array; }
44                 }
45
46                 public void Add (JsonValue item)
47                 {
48                         if (item == null)
49                                 throw new ArgumentNullException ("item");
50
51                         list.Add (item);
52                 }
53
54                 public void AddRange (IEnumerable<JsonValue> items)
55                 {
56                         if (items == null)
57                                 throw new ArgumentNullException ("items");
58
59                         list.AddRange (items);
60                 }
61
62                 public void AddRange (params JsonValue [] items)
63                 {
64                         if (items == null)
65                                 return;
66
67                         list.AddRange (items);
68                 }
69
70                 public void Clear ()
71                 {
72                         list.Clear ();
73                 }
74
75                 public bool Contains (JsonValue item)
76                 {
77                         return list.Contains (item);
78                 }
79
80                 public void CopyTo (JsonValue [] array, int arrayIndex)
81                 {
82                         list.CopyTo (array, arrayIndex);
83                 }
84
85                 public int IndexOf (JsonValue item)
86                 {
87                         return list.IndexOf (item);
88                 }
89
90                 public void Insert (int index, JsonValue item)
91                 {
92                         list.Insert (index, item);
93                 }
94
95                 public bool Remove (JsonValue item)
96                 {
97                         return list.Remove (item);
98                 }
99
100                 public void RemoveAt (int index)
101                 {
102                         list.RemoveAt (index);
103                 }
104
105                 public override void Save (Stream stream)
106                 {
107                         if (stream == null)
108                                 throw new ArgumentNullException ("stream");
109                         stream.WriteByte ((byte) '[');
110                         for (int i = 0; i < list.Count; i++) {
111                                 JsonValue v = list [i];
112                                 if (v != null)
113                                         v.Save (stream);
114                                 else {
115                                         stream.WriteByte ((byte) 'n');
116                                         stream.WriteByte ((byte) 'u');
117                                         stream.WriteByte ((byte) 'l');
118                                         stream.WriteByte ((byte) 'l');
119                                 }
120
121                                 if (i < Count - 1) {
122                                         stream.WriteByte ((byte) ',');
123                                         stream.WriteByte ((byte) ' ');
124                                 }
125                         }
126                         stream.WriteByte ((byte) ']');
127                 }
128
129                 IEnumerator<JsonValue> IEnumerable<JsonValue>.GetEnumerator ()
130                 {
131                         return list.GetEnumerator ();
132                 }
133
134                 IEnumerator IEnumerable.GetEnumerator ()
135                 {
136                         return list.GetEnumerator ();
137                 }
138         }
139 }