public void SerializeSimpleStruct() { // var c = new STStructSimple() { data = 1.1, label = "Some test", value = 100 }; var c = new STStructSimple(1); var clone = c.DeepClone(); Assert.AreEqual(c, clone); var arr = new[] { c, c, c }; var arrClone = arr.DeepClone(); for (int i = 0; i < arr.Length; i++) { Assert.AreEqual(arr[i], arrClone[i]); } var buf = new byte[256]; clone = this.SerializationClone(c, buf); Assert.AreEqual(c, clone); arrClone = this.SerializationClone(arr, buf); for (int i = 0; i < arr.Length; i++) { Assert.AreEqual(arr[i], arrClone[i]); } }
public void ClearNotRequired() { // test various classes for which Clear() is a no-op var s1 = new STStructSimple(100); var s2 = new STStructSimple(100); Assert.IsTrue(s1.Equals(s2)); Serializer.Clear(ref s1, new SerializationContext()); Assert.IsTrue(s1.Equals(s2)); var c1 = new STClass(FooEnum.One, 1, "one", new[] { 1.0 }); var c2 = new STClass(FooEnum.One, 1, "one", new[] { 1.0 }); Assert.IsTrue(c1.Same(c2)); Serializer.Clear(ref c1, new SerializationContext()); Assert.IsTrue(c1.Same(c2)); var sc1 = new STStructComplex(100); var sc2 = new STStructComplex(100); Assert.IsTrue(sc1.Same(sc2)); Serializer.Clear(ref sc1, new SerializationContext()); Assert.IsTrue(sc1.Same(sc2)); var arr = new STStructComplex[1]; arr[0] = sc1; Assert.IsTrue(sc1.Same(sc2)); Serializer.Clear(ref arr, new SerializationContext()); Assert.IsTrue(sc1.Same(sc2)); var list = new List <STStructComplex>(); list.Add(sc1); Assert.IsTrue(sc1.Same(sc2)); Serializer.Clear(ref list, new SerializationContext()); Assert.IsTrue(sc1.Same(sc2)); var dict = new Dictionary <int, STStructComplex>(); dict.Add(1, sc1); Assert.IsTrue(sc1.Same(sc2)); Serializer.Clear(ref dict, new SerializationContext()); Assert.IsTrue(sc1.Same(sc2)); }