AnyClone icon indicating copy to clipboard operation
AnyClone copied to clipboard

Does not deep copy mutable value types

Open jpmikkers opened this issue 1 year ago • 0 comments

Hi fellow deepcopy developer, when I ran your library against my unit tests (I was actually looking to benchmark it against the purely reflection based approach) an issue popped up: AnyClone v1.1.6 does not deep copy value types that contain references to mutable classes. Here's the unit test:

        [TestMethod]
        public void Copy_DeepCopiesMutableFieldsOfValueTypes()
        {
            // Tuple itself is a mutable valuetype, MySingleObject is a class
            var a = new Tuple<MySingleObject>(new MySingleObject());
            var b = AnyClone.CloneExtensions.Clone(a);
            Assert.AreNotSame(a.Item1, b.Item1);    // this assert fails
            Assert.AreEqual(a.Item1, b.Item1);
            Assert.AreEqual(a, b);
        }

In other words this will result in two copies of Tuple that share the same 'MySingleObject' instance.

jpmikkers avatar Sep 24 '22 22:09 jpmikkers