-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONArray.cs
More file actions
93 lines (83 loc) · 2.25 KB
/
Copy pathJSONArray.cs
File metadata and controls
93 lines (83 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System.Collections;
using System.Collections.Generic;
namespace HGSDK
{
public class JSONArray : JSONData, IEnumerable
{
private readonly List<JSONData> _list = new List<JSONData>();
public override JSONData this[int index]
{
get
{
if (index < 0 || index >= _list.Count)
return null;
return _list[index];
}
set
{
if (index < 0 || index >= _list.Count)
_list.Add(value);
else
_list[index] = value;
}
}
public override int Count
{
get { return _list.Count; }
}
public override void Add(string key, JSONData item)
{
_list.Add(item);
}
public override JSONData Remove(int index)
{
if (index < 0 || index >= _list.Count)
return null;
var tmp = _list[index];
_list.RemoveAt(index);
return tmp;
}
public override JSONData Remove(JSONData data)
{
_list.Remove(data);
return data;
}
public override IEnumerable<JSONData> Children
{
get
{
foreach (var data in _list)
yield return data;
}
}
public IEnumerator GetEnumerator()
{
return _list.GetEnumerator();
}
public override string ToString()
{
var result = "[ ";
foreach (var N in _list)
{
if (result.Length > 2)
result += ", ";
result += N.ToString();
}
result += " ]";
return result;
}
public override string ToString(string prefix)
{
var result = "[ ";
foreach (var N in _list)
{
if (result.Length > 3)
result += ", ";
result += "\n" + prefix + " ";
result += N.ToString(prefix + " ");
}
result += "\n" + prefix + "]";
return result;
}
}
}