Skip to content

Commit e7e2328

Browse files
committed
style: 为 JsonData.cs 所有控制流添加大括号
1 parent 877e810 commit e7e2328

1 file changed

Lines changed: 78 additions & 3 deletions

File tree

Runtime/JsonData.cs

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ object IDictionary.this[object key] {
209209

210210
set {
211211
if (! (key is String))
212+
{
212213
throw new ArgumentException (
213214
"The key has to be a string");
215+
}
214216

215217
JsonData data = ToJsonData (value);
216218

@@ -280,8 +282,9 @@ public JsonData this[string prop_name] {
280282
break;
281283
}
282284
}
283-
} else
285+
} else {
284286
object_list.Add (entry);
287+
}
285288

286289
inst_object[prop_name] = value;
287290

@@ -294,7 +297,9 @@ public JsonData this[int index] {
294297
EnsureCollection ();
295298

296299
if (type == JsonType.Array)
300+
{
297301
return inst_array[index];
302+
}
298303

299304
return object_list[index].Value;
300305
}
@@ -303,7 +308,9 @@ public JsonData this[int index] {
303308
EnsureCollection ();
304309

305310
if (type == JsonType.Array)
311+
{
306312
inst_array[index] = value;
313+
}
307314
else {
308315
KeyValuePair<string, JsonData> entry = object_list[index];
309316
KeyValuePair<string, JsonData> new_entry =
@@ -424,17 +431,21 @@ public static implicit operator JsonData (String data)
424431
public static explicit operator Boolean (JsonData data)
425432
{
426433
if (data.type != JsonType.Boolean)
434+
{
427435
throw new InvalidCastException (
428436
"Instance of JsonData doesn't hold a boolean");
437+
}
429438

430439
return data.inst_boolean;
431440
}
432441

433442
public static explicit operator Double (JsonData data)
434443
{
435444
if (data.type != JsonType.Double)
445+
{
436446
throw new InvalidCastException (
437447
"Instance of JsonData doesn't hold a double");
448+
}
438449

439450
return data.inst_double;
440451
}
@@ -465,8 +476,10 @@ public static explicit operator Int64(JsonData data)
465476
public static explicit operator String (JsonData data)
466477
{
467478
if (data.type != JsonType.String)
479+
{
468480
throw new InvalidCastException (
469481
"Instance of JsonData doesn't hold a string");
482+
}
470483

471484
return data.inst_string;
472485
}
@@ -540,44 +553,54 @@ IEnumerator IEnumerable.GetEnumerator ()
540553
bool IJsonWrapper.GetBoolean ()
541554
{
542555
if (type != JsonType.Boolean)
556+
{
543557
throw new InvalidOperationException (
544558
"JsonData instance doesn't hold a boolean");
559+
}
545560

546561
return inst_boolean;
547562
}
548563

549564
double IJsonWrapper.GetDouble ()
550565
{
551566
if (type != JsonType.Double)
567+
{
552568
throw new InvalidOperationException (
553569
"JsonData instance doesn't hold a double");
570+
}
554571

555572
return inst_double;
556573
}
557574

558575
int IJsonWrapper.GetInt ()
559576
{
560577
if (type != JsonType.Int)
578+
{
561579
throw new InvalidOperationException (
562580
"JsonData instance doesn't hold an int");
581+
}
563582

564583
return inst_int;
565584
}
566585

567586
long IJsonWrapper.GetLong ()
568587
{
569588
if (type != JsonType.Long)
589+
{
570590
throw new InvalidOperationException (
571591
"JsonData instance doesn't hold a long");
592+
}
572593

573594
return inst_long;
574595
}
575596

576597
string IJsonWrapper.GetString ()
577598
{
578599
if (type != JsonType.String)
600+
{
579601
throw new InvalidOperationException (
580602
"JsonData instance doesn't hold a string");
603+
}
581604

582605
return inst_string;
583606
}
@@ -707,10 +730,14 @@ void IOrderedDictionary.RemoveAt (int idx)
707730
private ICollection EnsureCollection ()
708731
{
709732
if (type == JsonType.Array)
733+
{
710734
return (ICollection) inst_array;
735+
}
711736

712737
if (type == JsonType.Object)
738+
{
713739
return (ICollection) inst_object;
740+
}
714741

715742
throw new InvalidOperationException (
716743
"The JsonData instance has to be initialized first");
@@ -719,11 +746,15 @@ private ICollection EnsureCollection ()
719746
private IDictionary EnsureDictionary ()
720747
{
721748
if (type == JsonType.Object)
749+
{
722750
return (IDictionary) inst_object;
751+
}
723752

724753
if (type != JsonType.None)
754+
{
725755
throw new InvalidOperationException (
726756
"Instance of JsonData is not a dictionary");
757+
}
727758

728759
type = JsonType.Object;
729760
inst_object = new Dictionary<string, JsonData> ();
@@ -735,11 +766,15 @@ private IDictionary EnsureDictionary ()
735766
private IList EnsureList ()
736767
{
737768
if (type == JsonType.Array)
769+
{
738770
return (IList) inst_array;
771+
}
739772

740773
if (type != JsonType.None)
774+
{
741775
throw new InvalidOperationException (
742776
"Instance of JsonData is not a list");
777+
}
743778

744779
type = JsonType.Array;
745780
inst_array = new List<JsonData> ();
@@ -750,10 +785,14 @@ private IList EnsureList ()
750785
private JsonData ToJsonData (object obj)
751786
{
752787
if (obj == null)
788+
{
753789
return null;
790+
}
754791

755792
if (obj is JsonData)
793+
{
756794
return (JsonData) obj;
795+
}
757796

758797
return new JsonData (obj);
759798
}
@@ -793,7 +832,9 @@ private static void WriteJson (IJsonWrapper obj, JsonWriter writer)
793832
if (obj.IsArray) {
794833
writer.WriteArrayStart ();
795834
foreach (object elem in (IList) obj)
835+
{
796836
WriteJson ((JsonData) elem, writer);
837+
}
797838
writer.WriteArrayEnd ();
798839

799840
return;
@@ -829,13 +870,19 @@ public bool Remove(object obj)
829870
if(IsObject)
830871
{
831872
if (!(obj is string key))
873+
{
832874
return false;
875+
}
833876

834877
JsonData value = null;
835878
if (inst_object.TryGetValue(key, out value))
879+
{
836880
return inst_object.Remove(key) && object_list.Remove(new KeyValuePair<string, JsonData>(key, value));
881+
}
837882
else
883+
{
838884
throw new KeyNotFoundException("The specified key was not found in the JsonData object.");
885+
}
839886
}
840887
if(IsArray)
841888
{
@@ -847,12 +894,14 @@ public bool Remove(object obj)
847894

848895
public void Clear ()
849896
{
850-
if (IsObject) {
897+
if (IsObject)
898+
{
851899
((IDictionary) this).Clear ();
852900
return;
853901
}
854902

855-
if (IsArray) {
903+
if (IsArray)
904+
{
856905
((IList) this).Clear ();
857906
return;
858907
}
@@ -861,7 +910,9 @@ public void Clear ()
861910
public bool Equals (JsonData x)
862911
{
863912
if (x == null)
913+
{
864914
return false;
915+
}
865916

866917
if (x.type != this.type)
867918
{
@@ -879,28 +930,42 @@ public bool Equals (JsonData x)
879930

880931
case JsonType.Object:
881932
if (x.inst_object == null || this.inst_object == null)
933+
{
882934
return x.inst_object == this.inst_object;
935+
}
883936
if (x.inst_object.Count != this.inst_object.Count)
937+
{
884938
return false;
939+
}
885940
foreach (var kvp in this.inst_object)
886941
{
887942
JsonData otherValue;
888943
if (!x.inst_object.TryGetValue(kvp.Key, out otherValue))
944+
{
889945
return false;
946+
}
890947
if (!kvp.Value.Equals(otherValue))
948+
{
891949
return false;
950+
}
892951
}
893952
return true;
894953

895954
case JsonType.Array:
896955
if (x.inst_array == null || this.inst_array == null)
956+
{
897957
return x.inst_array == this.inst_array;
958+
}
898959
if (x.inst_array.Count != this.inst_array.Count)
960+
{
899961
return false;
962+
}
900963
for (int i = 0; i < this.inst_array.Count; i++)
901964
{
902965
if (!this.inst_array[i].Equals(x.inst_array[i]))
966+
{
903967
return false;
968+
}
904969
}
905970
return true;
906971

@@ -912,7 +977,9 @@ public bool Equals (JsonData x)
912977
if (x.IsLong)
913978
{
914979
if (x.inst_long < Int32.MinValue || x.inst_long > Int32.MaxValue)
980+
{
915981
return false;
982+
}
916983
return this.inst_int.Equals((int)x.inst_long);
917984
}
918985
return this.inst_int.Equals(x.inst_int);
@@ -923,7 +990,9 @@ public bool Equals (JsonData x)
923990
if (x.IsInt)
924991
{
925992
if (this.inst_long < Int32.MinValue || this.inst_long > Int32.MaxValue)
993+
{
926994
return false;
995+
}
927996
return x.inst_int.Equals((int)this.inst_long);
928997
}
929998
return this.inst_long.Equals(x.inst_long);
@@ -947,7 +1016,9 @@ public JsonType GetJsonType ()
9471016
public void SetJsonType (JsonType type)
9481017
{
9491018
if (this.type == type)
1019+
{
9501020
return;
1021+
}
9511022

9521023
switch (type) {
9531024
case JsonType.None:
@@ -989,12 +1060,16 @@ public void SetJsonType (JsonType type)
9891060
public string ToJson ()
9901061
{
9911062
if (json != null)
1063+
{
9921064
return json;
1065+
}
9931066

9941067
lock (_writerLock)
9951068
{
9961069
if (json != null)
1070+
{
9971071
return json;
1072+
}
9981073

9991074
_writer.Reset();
10001075
_writer.Validate = false;

0 commit comments

Comments
 (0)