@@ -135,46 +135,62 @@ public JsonWriter(TextWriter writer)
135135 private void DoValidation ( Condition cond )
136136 {
137137 if ( ! context . ExpectingValue )
138+ {
138139 context . Count ++ ;
140+ }
139141
140142 if ( ! validate )
143+ {
141144 return ;
145+ }
142146
143147 if ( has_reached_end )
148+ {
144149 throw new JsonException (
145150 "A complete JSON symbol has already been written" ) ;
151+ }
146152
147153 switch ( cond )
148154 {
149155 case Condition . InArray :
150156 if ( ! context . InArray )
157+ {
151158 throw new JsonException (
152159 "Can't close an array here" ) ;
160+ }
153161 break ;
154162
155163 case Condition . InObject :
156164 if ( ! context . InObject || context . ExpectingValue )
165+ {
157166 throw new JsonException (
158167 "Can't close an object here" ) ;
168+ }
159169 break ;
160170
161171 case Condition . NotAProperty :
162172 if ( context . InObject && ! context . ExpectingValue )
173+ {
163174 throw new JsonException (
164175 "Expected a property" ) ;
176+ }
165177 break ;
166178
167179 case Condition . Property :
168180 if ( ! context . InObject || context . ExpectingValue )
181+ {
169182 throw new JsonException (
170183 "Can't add a property here" ) ;
184+ }
171185 break ;
172186
173187 case Condition . Value :
174188 if ( ! context . InArray &&
175189 ( ! context . InObject || ! context . ExpectingValue ) )
190+ {
176191 throw new JsonException (
177192 "Can't add a value here" ) ;
193+ }
178194
179195 break ;
180196 }
@@ -204,9 +220,13 @@ private static void IntToHex(int n, char[] hex)
204220 num = n % 16 ;
205221
206222 if ( num < 10 )
223+ {
207224 hex [ 3 - i ] = ( char ) ( '0' + num ) ;
225+ }
208226 else
227+ {
209228 hex [ 3 - i ] = ( char ) ( 'A' + ( num - 10 ) ) ;
229+ }
210230
211231 n >>= 4 ;
212232 }
@@ -397,9 +417,13 @@ public void Write(string str)
397417 PutNewline ( ) ;
398418
399419 if ( str == null )
420+ {
400421 Put ( "null" ) ;
422+ }
401423 else
424+ {
402425 PutString ( str ) ;
426+ }
403427
404428 context . ExpectingValue = false ;
405429 }
@@ -422,7 +446,9 @@ public void WriteArrayEnd()
422446
423447 ctx_stack . Pop ( ) ;
424448 if ( ctx_stack . Count == 1 )
449+ {
425450 has_reached_end = true ;
451+ }
426452 else
427453 {
428454 context = ctx_stack . Peek ( ) ;
@@ -454,7 +480,9 @@ public void WriteObjectEnd()
454480
455481 ctx_stack . Pop ( ) ;
456482 if ( ctx_stack . Count == 1 )
483+ {
457484 has_reached_end = true ;
485+ }
458486 else
459487 {
460488 context = ctx_stack . Peek ( ) ;
@@ -497,12 +525,16 @@ public void WritePropertyName(string property_name)
497525 for ( int i = context . Padding - propertyName . Length ;
498526 i >= 0 ;
499527 i -- )
528+ {
500529 writer . Write ( ' ' ) ;
530+ }
501531
502532 writer . Write ( ": " ) ;
503533 }
504534 else
535+ {
505536 writer . Write ( ':' ) ;
537+ }
506538
507539 context . ExpectingValue = true ;
508540 }
0 commit comments