annotate Implab/JSON/JSONWriter.cs @ 129:471f596b2603 v2

Added SharedLock to synchronization routines
author cin
date Thu, 29 Jan 2015 18:31:06 +0300
parents 2573b562e328
children 0fa293bb1351
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
1 using System;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
2 using System.Collections.Generic;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
3 using System.IO;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
4
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
5 namespace Implab.JSON {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
6 public class JSONWriter {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
7 struct Context {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
8 public bool needComma;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
9 public JSONElementContext element;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
10 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
11 Stack<Context> m_contextStack = new Stack<Context>();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
12 Context m_context;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
13
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
14 TextWriter m_writer;
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
15 readonly bool m_indent = true;
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
16 readonly int m_indentSize = 4;
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
17
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
18 static readonly char [] _escapeBKS,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
19 _escapeFWD,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
20 _escapeCR,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
21 _escapeNL,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
22 _escapeTAB,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
23 _escapeBSLASH,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
24 _escapeQ;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
25
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
26 static JSONWriter() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
27 _escapeBKS = "\\b".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
28 _escapeFWD = "\\f".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
29 _escapeCR = "\\r".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
30 _escapeNL = "\\n".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
31 _escapeTAB = "\\t".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
32 _escapeBSLASH = "\\\\".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
33 _escapeQ = "\\\"".ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
34 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
35
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
36 public JSONWriter(TextWriter writer) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
37 Safe.ArgumentNotNull(writer, "writer");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
38
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
39 m_writer = writer;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
40 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
41
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
42 public JSONWriter(TextWriter writer, bool indent) {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
43 Safe.ArgumentNotNull(writer, "writer");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
44
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
45 m_writer = writer;
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
46 m_indent = indent;
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
47 }
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
48
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
49 void WriteIndent() {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
50 if (m_indent) {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
51 var indent = new char[m_contextStack.Count * m_indentSize + 1];
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
52 indent[0] = '\n';
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
53 for (int i = 1; i < indent.Length; i++)
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
54 indent[i] = ' ';
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
55 m_writer.Write(new String(indent));
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
56 } else {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
57 m_writer.Write(' ');
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
58 }
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
59 }
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
60
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
61 void WriteMemberName(string name) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
62 Safe.ArgumentNotEmpty(name, "name");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
63 if (m_context.element != JSONElementContext.Object)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
64 OperationNotApplicable("WriteMember");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
65 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
66 m_writer.Write(",");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
67
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
68 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
69 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
70 Write(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
71 m_writer.Write(" : ");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
72 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
73
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
74 public void WriteValue(string name, string value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
75 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
76 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
77 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
78
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
79 public void WriteValue(string name, bool value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
80 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
81 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
82 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
83
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
84 public void WriteValue(string name, double value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
85 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
86 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
87 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
88
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
89 public void WriteValue(string value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
90 if (m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
91 OperationNotApplicable("WriteValue");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
92 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
93 m_writer.Write(",");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
94 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
95 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
96
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
97 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
98 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
99
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
100 public void WriteValue(bool value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
101 if (m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
102 OperationNotApplicable("WriteValue");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
103 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
104 m_writer.Write(",");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
105 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
106
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
107 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
108 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
109 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
110
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
111 public void WriteValue(double value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
112 if (m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
113 OperationNotApplicable("WriteValue");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
114 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
115 m_writer.Write(",");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
116 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
117
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
118 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
119 Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
120 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
121
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
122 public void BeginObject() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
123 if (m_context.element != JSONElementContext.None && m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
124 OperationNotApplicable("BeginObject");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
125 if (m_context.needComma)
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
126 m_writer.Write(",");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
127
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
128 WriteIndent();
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
129
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
130 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
131
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
132 m_contextStack.Push(m_context);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
133
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
134 m_context = new Context { element = JSONElementContext.Object, needComma = false };
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
135 m_writer.Write("{");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
136 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
137
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
138 public void BeginObject(string name) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
139 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
140
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
141 m_contextStack.Push(m_context);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
142
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
143 m_context = new Context { element = JSONElementContext.Object, needComma = false };
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
144 m_writer.Write("{");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
145 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
146
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
147 public void EndObject() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
148 if (m_context.element != JSONElementContext.Object)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
149 OperationNotApplicable("EndArray");
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
150
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
151 m_context = m_contextStack.Pop();
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
152 WriteIndent();
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
153 m_writer.Write("}");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
154 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
155
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
156 public void BeginArray() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
157 if (m_context.element != JSONElementContext.None && m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
158 throw new InvalidOperationException();
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
159 if (m_context.needComma) {
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
160 m_writer.Write(",");
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
161
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
162 }
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
163 m_context.needComma = true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
164
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
165 WriteIndent();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
166 m_contextStack.Push(m_context);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
167 m_context = new Context { element = JSONElementContext.Array, needComma = false };
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
168 m_writer.Write("[");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
169 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
170
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
171 public void BeginArray(string name) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
172 WriteMemberName(name);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
173
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
174 m_contextStack.Push(m_context);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
175
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
176 m_context = new Context { element = JSONElementContext.Array, needComma = false };
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
177 m_writer.Write("[");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
178 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
179
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
180 public void EndArray() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
181 if (m_context.element != JSONElementContext.Array)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
182 OperationNotApplicable("EndArray");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
183
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
184 m_context = m_contextStack.Pop();
72
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
185 WriteIndent();
d67b95eddaf4 promises refactoring
cin
parents: 55
diff changeset
186 m_writer.Write("]");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
187 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
188
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
189 void Write(bool value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
190 m_writer.Write(value ? "true" : "false");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
191 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
192
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
193
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
194 void Write(string value) {
115
ffd3702968c7 fixed JSON writer
cin
parents: 72
diff changeset
195 if (value == null) {
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
196 m_writer.Write("null");
115
ffd3702968c7 fixed JSON writer
cin
parents: 72
diff changeset
197 return;
ffd3702968c7 fixed JSON writer
cin
parents: 72
diff changeset
198 }
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
199
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
200 var chars = value.ToCharArray();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
201 m_writer.Write('"');
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
202
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 118
diff changeset
203 // Analysis disable once ForCanBeConvertedToForeach
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
204 for (int i = 0; i < chars.Length; i++) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
205 var ch = chars[i];
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
206
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
207 switch (ch) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
208 case '\b':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
209 m_writer.Write(_escapeBKS);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
210 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
211 case '\f':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
212 m_writer.Write(_escapeFWD);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
213 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
214 case '\r':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
215 m_writer.Write(_escapeCR);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
216 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
217 case '\n':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
218 m_writer.Write(_escapeNL);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
219 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
220 case '\t':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
221 m_writer.Write(_escapeTAB);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
222 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
223 case '\\':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
224 m_writer.Write(_escapeBSLASH);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
225 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
226 case '"':
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
227 m_writer.Write(_escapeQ);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
228 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
229 default:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
230 if (ch < 0x20) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
231 m_writer.Write("\\u00{0:x2}",(int)ch);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
232 } else {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
233 m_writer.Write(ch);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
234 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
235 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
236 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
237 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
238
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
239 m_writer.Write('"');
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
240 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
241
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
242 void Write(double value) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
243 m_writer.Write(value);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
244 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
245
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
246 void OperationNotApplicable(string opName) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
247 throw new InvalidOperationException(String.Format("The operation '{0}' isn't applicable in the context of '{1}'", opName, m_context.element ));
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
248 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
249
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
250 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
251 }