public void DeepClone_ArrayOfPrimitiveRef_NotAsReference(TypeModel model) { var manualModel = TypeModel.Create(); var metaType = manualModel.Add(typeof (ArrayOfPrimitiveRef), true); metaType.AddField(1, "Collection1"); metaType.AddField(2, "Collection2"); var collection = new int[] { 2, 5 }; var array = new ArrayOfPrimitiveRef() { Collection1 = collection, Collection2 = collection }; var clone = (ArrayOfPrimitiveRef)manualModel.DeepClone(array); Assert.IsTrue(object.ReferenceEquals(array.Collection1, array.Collection2)); Assert.AreEqual(array.Collection1.Length, clone.Collection1.Length); Assert.AreEqual(array.Collection2.Length, clone.Collection2.Length); Assert.AreEqual(array.Collection1[0], clone.Collection1[0]); Assert.AreEqual(array.Collection1[1], clone.Collection1[1]); Assert.AreEqual(array.Collection2[0], clone.Collection2[0]); Assert.AreEqual(array.Collection2[1], clone.Collection2[1]); Assert.IsFalse(object.ReferenceEquals(clone.Collection1, clone.Collection2), "Clone reference kept"); clone.Collection1[1] = 7; Assert.AreNotEqual(clone.Collection1[1], clone.Collection2[1]); }
public void DeepClone_ArrayOfPrimitiveRef_AsReference(TypeModel model) { var collection = new int[] { 2, 5 }; var array = new ArrayOfPrimitiveRef() { Collection1 = collection, Collection2 = collection }; var clone = (ArrayOfPrimitiveRef)model.DeepClone(array); Assert.IsTrue(object.ReferenceEquals(array.Collection1, array.Collection2)); Assert.AreEqual(array.Collection1.Length, clone.Collection1.Length); Assert.AreEqual(array.Collection2.Length, clone.Collection2.Length); Assert.AreEqual(array.Collection1[0], clone.Collection1[0]); Assert.AreEqual(array.Collection1[1], clone.Collection1[1]); Assert.AreEqual(array.Collection2[0], clone.Collection2[0]); Assert.AreEqual(array.Collection2[1], clone.Collection2[1]); Assert.IsTrue(object.ReferenceEquals(clone.Collection1, clone.Collection2), "Clone reference lost"); clone.Collection1[1] = 7; Assert.AreEqual(clone.Collection1[1], clone.Collection2[1]); }