@@ -1,7 +1,4 | |||||
1 | using System; |
|
1 | using System; | |
2 | using System.Collections.Generic; |
|
|||
3 | using System.Linq; |
|
|||
4 | using System.Text; |
|
|||
5 |
|
2 | |||
6 | namespace Implab { |
|
3 | namespace Implab { | |
7 | public interface ICancellable { |
|
4 | public interface ICancellable { |
@@ -11,6 +11,7 namespace Implab.JSON { | |||||
11 | public enum JSONElementContext { |
|
11 | public enum JSONElementContext { | |
12 | None, |
|
12 | None, | |
13 | Object, |
|
13 | Object, | |
14 | Array |
|
14 | Array, | |
|
15 | Closed | |||
15 | } |
|
16 | } | |
16 | } |
|
17 | } |
@@ -87,36 +87,54 namespace Implab.JSON { | |||||
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | public void WriteValue(string value) { |
|
89 | public void WriteValue(string value) { | |
90 |
if (m_context.element |
|
90 | if (m_context.element == JSONElementContext.Array) { | |
|
91 | ||||
|
92 | if (m_context.needComma) | |||
|
93 | m_writer.Write(","); | |||
|
94 | WriteIndent(); | |||
|
95 | m_context.needComma = true; | |||
|
96 | ||||
|
97 | Write(value); | |||
|
98 | } else if (m_context.element == JSONElementContext.None) { | |||
|
99 | Write(value); | |||
|
100 | m_context.element = JSONElementContext.Closed; | |||
|
101 | } else { | |||
91 | OperationNotApplicable("WriteValue"); |
|
102 | OperationNotApplicable("WriteValue"); | |
92 | if (m_context.needComma) |
|
103 | } | |
93 | m_writer.Write(","); |
|
|||
94 | WriteIndent(); |
|
|||
95 | m_context.needComma = true; |
|
|||
96 |
|
||||
97 | Write(value); |
|
|||
98 | } |
|
104 | } | |
99 |
|
105 | |||
100 | public void WriteValue(bool value) { |
|
106 | public void WriteValue(bool value) { | |
101 |
if (m_context.element |
|
107 | if (m_context.element == JSONElementContext.Array) { | |
|
108 | ||||
|
109 | if (m_context.needComma) | |||
|
110 | m_writer.Write(","); | |||
|
111 | WriteIndent(); | |||
|
112 | m_context.needComma = true; | |||
|
113 | ||||
|
114 | Write(value); | |||
|
115 | } else if (m_context.element == JSONElementContext.None) { | |||
|
116 | Write(value); | |||
|
117 | m_context.element = JSONElementContext.Closed; | |||
|
118 | } else { | |||
102 | OperationNotApplicable("WriteValue"); |
|
119 | OperationNotApplicable("WriteValue"); | |
103 | if (m_context.needComma) |
|
120 | } | |
104 | m_writer.Write(","); |
|
|||
105 | m_context.needComma = true; |
|
|||
106 |
|
||||
107 | WriteIndent(); |
|
|||
108 | Write(value); |
|
|||
109 | } |
|
121 | } | |
110 |
|
122 | |||
111 | public void WriteValue(double value) { |
|
123 | public void WriteValue(double value) { | |
112 |
if (m_context.element |
|
124 | if (m_context.element == JSONElementContext.Array) { | |
|
125 | ||||
|
126 | if (m_context.needComma) | |||
|
127 | m_writer.Write(","); | |||
|
128 | WriteIndent(); | |||
|
129 | m_context.needComma = true; | |||
|
130 | ||||
|
131 | Write(value); | |||
|
132 | } else if (m_context.element == JSONElementContext.None) { | |||
|
133 | Write(value); | |||
|
134 | m_context.element = JSONElementContext.Closed; | |||
|
135 | } else { | |||
113 | OperationNotApplicable("WriteValue"); |
|
136 | OperationNotApplicable("WriteValue"); | |
114 | if (m_context.needComma) |
|
137 | } | |
115 | m_writer.Write(","); |
|
|||
116 | m_context.needComma = true; |
|
|||
117 |
|
||||
118 | WriteIndent(); |
|
|||
119 | Write(value); |
|
|||
120 | } |
|
138 | } | |
121 |
|
139 | |||
122 | public void BeginObject() { |
|
140 | public void BeginObject() { | |
@@ -146,9 +164,11 namespace Implab.JSON { | |||||
146 |
|
164 | |||
147 | public void EndObject() { |
|
165 | public void EndObject() { | |
148 | if (m_context.element != JSONElementContext.Object) |
|
166 | if (m_context.element != JSONElementContext.Object) | |
149 |
OperationNotApplicable("End |
|
167 | OperationNotApplicable("EndObject"); | |
150 |
|
168 | |||
151 | m_context = m_contextStack.Pop(); |
|
169 | m_context = m_contextStack.Pop(); | |
|
170 | if (m_contextStack.Count == 0) | |||
|
171 | m_context.element = JSONElementContext.Closed; | |||
152 | WriteIndent(); |
|
172 | WriteIndent(); | |
153 | m_writer.Write("}"); |
|
173 | m_writer.Write("}"); | |
154 | } |
|
174 | } | |
@@ -182,6 +202,8 namespace Implab.JSON { | |||||
182 | OperationNotApplicable("EndArray"); |
|
202 | OperationNotApplicable("EndArray"); | |
183 |
|
203 | |||
184 | m_context = m_contextStack.Pop(); |
|
204 | m_context = m_contextStack.Pop(); | |
|
205 | if (m_contextStack.Count == 0) | |||
|
206 | m_context.element = JSONElementContext.Closed; | |||
185 | WriteIndent(); |
|
207 | WriteIndent(); | |
186 | m_writer.Write("]"); |
|
208 | m_writer.Write("]"); | |
187 | } |
|
209 | } |
General Comments 0
You need to be logged in to leave comments.
Login now