forked from ln-dotnet/ln.json
112 lines
1.8 KiB
C#
112 lines
1.8 KiB
C#
using System;
|
|
using System.Text;
|
|
using System.Collections.Generic;
|
|
|
|
namespace sharp.json
|
|
{
|
|
public class JSONArray : JSON
|
|
{
|
|
public JSONArray()
|
|
: base(JSONTypes.Array) { }
|
|
|
|
public JSONArray(object[] init)
|
|
: base(JSONTypes.Array)
|
|
{
|
|
foreach (object o in init)
|
|
{
|
|
this.values.Add(JSONConverter.From(o));
|
|
}
|
|
|
|
}
|
|
|
|
List<JSON> values = new List<JSON>();
|
|
|
|
public override bool Boolean
|
|
{
|
|
get { return values.Count > 0; }
|
|
}
|
|
|
|
public override JSON this[int n]
|
|
{
|
|
get
|
|
{
|
|
return values[n];
|
|
}
|
|
set
|
|
{
|
|
values[n] = value;
|
|
}
|
|
}
|
|
|
|
public override int Count
|
|
{
|
|
get
|
|
{
|
|
return this.values.Count;
|
|
}
|
|
}
|
|
|
|
public override bool Contains(object o)
|
|
{
|
|
return this.values.Contains((JSON)o);
|
|
}
|
|
|
|
public override void Add(JSON child)
|
|
{
|
|
this.values.Add(child);
|
|
}
|
|
|
|
public override void Remove(JSON child)
|
|
{
|
|
this.values.Remove(child);
|
|
}
|
|
|
|
public override string[] prettyPrint()
|
|
{
|
|
List<string> lines = new List<string>();
|
|
|
|
lines.Add("[");
|
|
|
|
for (int i = 0; i < this.values.Count; i++)
|
|
{
|
|
JSON cv = this.values[i];
|
|
string[] clines = cv.prettyPrint();
|
|
|
|
for (int n = 0; n < clines.Length; n++)
|
|
{
|
|
lines.Add(String.Format(" {0}{1}", clines[n], (n < clines.Length - 1) || (i == this.values.Count - 1) ? "" : ","));
|
|
}
|
|
}
|
|
|
|
lines.Add("]");
|
|
|
|
return lines.ToArray();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append("[");
|
|
for (int n = 0; n < this.Count; n++)
|
|
{
|
|
sb.Append(this[n].ToString());
|
|
if (n + 1 < this.Count)
|
|
{
|
|
sb.Append(",");
|
|
}
|
|
}
|
|
sb.Append("]");
|
|
return sb.ToString();
|
|
}
|
|
|
|
|
|
|
|
public override IEnumerator<JSON> GetEnumerator()
|
|
{
|
|
return this.values.GetEnumerator();
|
|
}
|
|
|
|
|
|
}
|
|
}
|