Example #1
0
 private void ReadNull(ref JReader r, ValueVariant variant)
 {
     if (variant == NullableBoolIsNull)
     {
         RequireNull(r.BoolOrNull());
     }
     else if (variant == NullableIntIsNull)
     {
         RequireNull(r.IntOrNull());
     }
     else if (variant == NullableLongIsNull)
     {
         RequireNull(r.LongOrNull());
     }
     else if (variant == NullableDoubleIsNull)
     {
         RequireNull(r.DoubleOrNull());
     }
     else if (variant == NullableStringIsNull)
     {
         Assert.True(r.StringOrNull() == null, "expected null");
     }
     else if (variant == NullableArrayIsNull)
     {
         Assert.False(r.ArrayOrNull().IsDefined, "expected null");
     }
     else if (variant == NullableObjectIsNull)
     {
         Assert.False(r.ObjectOrNull().IsDefined, "expected null");
     }
     else
     {
         r.Null();
     }
 }
Example #2
0
            public object ReadJson(ref JReader reader)
            {
                var ret = new MyTestClass();

                for (var obj = reader.Object(); obj.Next(ref reader);)
                {
                    switch (obj.Name.ToString())
                    {
                    case "stringProp":
                        ret.StringProp = reader.String();
                        break;

                    case "boolProp":
                        ret.BoolProp = reader.Bool();
                        break;

                    case "intProp":
                        ret.IntProp = reader.Int();
                        break;

                    case "longProp":
                        ret.LongProp = reader.Long();
                        break;

                    case "doubleProp":
                        ret.DoubleProp = reader.Double();
                        break;

                    case "arrayOfInts":
                        ret.ArrayOfInts = new List <int>();
                        for (var arr = reader.Array(); arr.Next(ref reader);)
                        {
                            ret.ArrayOfInts.Add(reader.Int());
                        }
                        break;

                    case "objectOfInts":
                        ret.ObjectOfInts = new Dictionary <string, int>();
                        for (var subObj = reader.Object(); subObj.Next(ref reader);)
                        {
                            ret.ObjectOfInts[subObj.Name.ToString()] = reader.Int();
                        }
                        break;

                    case "nullableString1":
                        ret.NullableString1 = reader.StringOrNull();
                        break;

                    case "nullableBool1":
                        ret.NullableBool1 = reader.BoolOrNull();
                        break;

                    case "nullableInt1":
                        ret.NullableInt1 = reader.IntOrNull();
                        break;

                    case "nullableLong1":
                        ret.NullableLong1 = reader.LongOrNull();
                        break;

                    case "nullableDouble1":
                        ret.NullableDouble1 = reader.DoubleOrNull();
                        break;

                    case "nullableString2":
                        ret.NullableString2 = reader.StringOrNull();
                        break;

                    case "nullableBool2":
                        ret.NullableBool2 = reader.BoolOrNull();
                        break;

                    case "nullableInt2":
                        ret.NullableInt2 = reader.IntOrNull();
                        break;

                    case "nullableLong2":
                        ret.NullableLong2 = reader.LongOrNull();
                        break;

                    case "nullableDouble2":
                        ret.NullableDouble2 = reader.DoubleOrNull();
                        break;
                    }
                }
                return(ret);
            }