using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace SUISS.Cloud.Boomlagoon.JSON { public class JSONArray : IEnumerable, IEnumerable { public JSONArray() { } public JSONArray(JSONArray array) { this.values = new List(); foreach (JSONValue value in array.values) { this.values.Add(new JSONValue(value)); } } public void Add(JSONValue value) { this.values.Add(value); } public JSONValue this[int index] { get { return this.values[index]; } set { this.values[index] = value; } } public int Length { get { return this.values.Count; } } public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('['); foreach (JSONValue jsonvalue in this.values) { stringBuilder.Append(jsonvalue.ToString()); stringBuilder.Append(','); } if (this.values.Count > 0) { stringBuilder.Remove(stringBuilder.Length - 1, 1); } stringBuilder.Append(']'); return stringBuilder.ToString(); } public IEnumerator GetEnumerator() { return this.values.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return this.values.GetEnumerator(); } public static JSONArray Parse(string jsonString) { JSONObject jsonobject = JSONObject.Parse("{ \"array\" :" + jsonString + "}"); return (jsonobject != null) ? jsonobject.GetValue("array").Array : null; } public void Clear() { this.values.Clear(); } public void Remove(int index) { if (index >= 0 && index < this.values.Count) { this.values.RemoveAt(index); } else { JSONLogger.Error(string.Format("index out of range: {0} (Expected 0 <= index < {1})", index, this.values.Count)); } } public static JSONArray operator +(JSONArray lhs, JSONArray rhs) { JSONArray jsonarray = new JSONArray(lhs); foreach (JSONValue value in rhs.values) { jsonarray.Add(value); } return jsonarray; } private readonly List values = new List(); } }