public void DeepClone_ClassWithFieldsRef_AsReference(TypeModel model) { var classWithFields = new ClassWithFieldsRef(); var item = new ItemClass() { Message = "Hi there!" }; classWithFields._item1 = item; classWithFields._item2 = item; var list = new List<int> { 2, 4, 5 }; classWithFields._list1 = list; classWithFields._list2 = list; var clone = (ClassWithFieldsRef)model.DeepClone(classWithFields); Assert.AreEqual(classWithFields._item1.Message, clone._item1.Message); Assert.AreEqual(classWithFields._item2.Message, clone._item2.Message); Assert.AreEqual(classWithFields._list1.Count, clone._list1.Count); for (int i = 0; i < classWithFields._list1.Count; i++) { Assert.AreEqual(classWithFields._list1[i], clone._list1[i]); } Assert.AreEqual(classWithFields._list2.Count, clone._list2.Count); for (int i = 0; i < classWithFields._list2.Count; i++) { Assert.AreEqual(classWithFields._list2[i], clone._list2[i]); } Assert.IsTrue(object.ReferenceEquals(classWithFields._item1, classWithFields._item2)); Assert.IsTrue(object.ReferenceEquals(classWithFields._list1, classWithFields._list2)); Assert.IsTrue(object.ReferenceEquals(clone._item1, clone._item2)); Assert.IsTrue(object.ReferenceEquals(clone._list1, clone._list2)); }
public void DeepClone_ClassWithFieldsRef_NotAsReference(TypeModel model) { var manualMode = TypeModel.Create(); var metaType = manualMode.Add(typeof(ClassWithFieldsRef), true); metaType.AddField(1, "_item1"); metaType.AddField(2, "_item2"); metaType.AddField(3, "_list1", typeof(int), null); metaType.AddField(4, "_list2", typeof(int), null); manualMode.Add(typeof(ItemClass), true).AddField(1, "Message"); var classWithFields = new ClassWithFieldsRef(); var item = new ItemClass() { Message = "Hi there!" }; classWithFields._item1 = item; classWithFields._item2 = item; var list = new List<int> { 2, 4, 5 }; classWithFields._list1 = list; classWithFields._list2 = list; var clone = (ClassWithFieldsRef)manualMode.DeepClone(classWithFields); Assert.AreEqual(classWithFields._item1.Message, clone._item1.Message); Assert.AreEqual(classWithFields._item2.Message, clone._item2.Message); Assert.AreEqual(classWithFields._list1.Count, clone._list1.Count); for (int i = 0; i < classWithFields._list1.Count; i++) { Assert.AreEqual(classWithFields._list1[i], clone._list1[i]); } Assert.AreEqual(classWithFields._list2.Count, clone._list2.Count); for (int i = 0; i < classWithFields._list2.Count; i++) { Assert.AreEqual(classWithFields._list2[i], clone._list2[i]); } Assert.IsTrue(object.ReferenceEquals(classWithFields._item1, classWithFields._item2)); Assert.IsTrue(object.ReferenceEquals(classWithFields._list1, classWithFields._list2)); Assert.IsFalse(object.ReferenceEquals(clone._item1, clone._item2)); Assert.IsFalse(object.ReferenceEquals(clone._list1, clone._list2)); }