public void SerializeComplexStruct() { var c = new STStructComplex(1001); var clone = c.DeepClone(); Assert.IsTrue(c.IsDeepClone(clone)); var arr = new[] { c, c, c }; var arrClone = arr.DeepClone(); for (int i = 0; i < arr.Length; i++) { Assert.IsTrue(arr[i].IsDeepClone(arrClone[i])); } var buf = new byte[256]; clone = this.SerializationClone(c, buf); Assert.IsTrue(c.IsDeepClone(clone)); arrClone = this.SerializationClone(arr, buf); for (int i = 0; i < arr.Length; i++) { Assert.IsTrue(arr[i].IsDeepClone(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)); }
public bool IsDeepClone(STStructComplex that) { return(this.Same(that) && !ReferenceEquals(this.internalValue, that.internalValue)); }
public bool Same(STStructComplex that) { return(this.Value == that.Value && this.internalValue.Same(that.internalValue)); }