public void TestNullable() { var js = new JsonSerializer(); js.JsonOptions.Indent = ""; js.JsonOptions.FieldSeparator = ""; var jd = new JsonDeserializer(); var v1 = new SampleNullable { N = null }; var result1 = js.ToString(v1); Assert.AreEqual("{\"N\":null}", result1); var w1 = jd.FromString<SampleNullable>(result1); Assert.AreEqual(v1.N, w1.N); var w1g = (SampleNullable)SampleNullable_JsonDeserializer.Instance.FromString(result1); Assert.AreEqual(v1.N, w1g.N); var v2 = new SampleNullable { N = 997 }; var result2 = js.ToString(v2); Assert.AreEqual("{\"N\":997}", result2); var w2 = jd.FromString<SampleNullable>(result2); Assert.AreEqual(v2.N, w2.N); var w2g = (SampleNullable)SampleNullable_JsonDeserializer.Instance.FromString(result2); Assert.AreEqual(v2.N, w2g.N); var v3 = new List<SamplePoint?> { new SamplePoint { X = -1, Y = -2 }, null }; var result3 = js.ToString(v3); Assert.AreEqual("[[-1,-2],null]", result3); var w3 = jd.FromString<List<SamplePoint?>>(result3); Assert.AreEqual(v3.Count, w3.Count); Assert.AreEqual(v3[0].Value.X, w3[0].Value.X); Assert.AreEqual(v3[0].Value.Y, w3[0].Value.Y); Assert.IsNull(w3[1]); }
public void TestNullable() { var bs = new BinarySerializer(); var bd = new BinaryDeserializer(); var bdg = new BinaryDeserializerGen(); var v1 = new SampleNullable { N = null }; var result1 = bs.ToBytes(v1); Assert.AreEqual( "20 01 00 " + XS(typeof(SampleNullable)) + " 01 00 " + XS("N", RoughType.Nullable) + " 05 " + "01 00 01 00 00", XS(result1)); var w1 = bd.FromBytes<SampleNullable>(result1); Assert.AreEqual(v1.N, w1.N); var w1g = bdg.FromBytes<SampleNullable>(result1); Assert.AreEqual(v1.N, w1g.N); var v2 = new SampleNullable { N = 997 }; var result2 = bs.ToBytes(v2); Assert.AreEqual( "20 01 00 01 00 00 E5 03 00 00 00 00", XS(result2)); var w2 = bd.FromBytes<SampleNullable>(result2); Assert.AreEqual(v2.N, w2.N); var w2g = bdg.FromBytes<SampleNullable>(result2); Assert.AreEqual(v2.N, w2g.N); var v3 = new List<SamplePoint?> { new SamplePoint { X = -1, Y = -2 }, null }; var result3 = bs.ToBytes(v3); Assert.AreEqual( "21 12 20 02 00 00 00 00 02 00 " + XS(typeof(SamplePoint)) + " 02 00 " + XS("X", RoughType.Int, "Y", RoughType.Int) + " FF FF FF FF FE FF FF FF 01", XS(result3)); var w3 = bd.FromBytes<List<SamplePoint?>>(result3); Assert.AreEqual(v3.Count, w3.Count); Assert.AreEqual(v3[0].Value.X, w3[0].Value.X); Assert.AreEqual(v3[0].Value.Y, w3[0].Value.Y); Assert.IsNull(w3[1]); }