public void BasicPasses() { var src = new TestBasicClass() { v1 = 1, sub = new TestBasicSubClass { v1 = -1, v2 = "v2 in sub" }, sub2 = new TestBasicSubClass2 { v1 = 111, v2 = "vvvidv" }, arr = new int[] { -1, -2, -3 }, list = new List <string> { "App", "Ora" }, }; var serializer = new JsonSerializer(); var stringWriter = new StringWriter(); serializer.Serialize(stringWriter, src); var json = stringWriter.ToString(); //Debug.Log($"debug-- '{json}'"); var reader = new StringReader(json); var dest = serializer.Deserialize(reader, typeof(TestBasicClass)) as TestBasicClass; src.AssertAreSame(dest); var stringWriter2 = new StringWriter(); serializer.Serialize(stringWriter2, dest); Assert.AreEqual(json, stringWriter2.ToString()); }
#pragma warning restore CS0649 public void AssertAreSame(TestBasicClass other) { Assert.AreEqual(this.v1, other.v1); Assert.AreEqual(this.v2, other.v2); sub.AssertAreSame(other.sub); sub2.AssertAreSame(other.sub2); Assert.AreEqual(arr.Length, other.arr.Length); foreach (var pair in arr.Zip(other.arr, (_t, _o) => (_t, _o))) { Assert.AreEqual(pair._t, pair._o); } }