DeepCopy icon indicating copy to clipboard operation
DeepCopy copied to clipboard

Type include interface field

Open tangdf opened this issue 6 years ago • 2 comments

        private class MyClass
        {
            public readonly ICollection<string> Collection = new List<string>();
        }

        [Fact]
        public void CanCopyInterfaceField()
        {
            MyClass original = new MyClass();

            original.Collection.Add("A");

            var result = DeepCopier.Copy(original);

            Assert.NotSame(original, result); //Failure
            Assert.NotSame(original.Collection, result.Collection); //Failure
        }

The result is failure.

tangdf avatar Nov 28 '17 10:11 tangdf

        [Fact]
        public void CanCopyInterfaceField()
        {
            MyObject o = new MyObject();

            MyClass original = new MyClass {
                Field1 = o,
                Field2 = o
            };

            var result = DeepCopier.Copy(original);

            Assert.Same(original.Field1, original.Field2); // OK

            Assert.Same(result.Field1, result.Field2); //Failure

        }



        public class MyClass
        {
            public IMyInterface1 Field1;
            public IMyInterface2 Field2;
        }

        public interface IMyInterface1
        {
            
        }
        public interface IMyInterface2
        {

        }
        public class MyObject: IMyInterface1, IMyInterface2
        {
            
        }

tangdf avatar Dec 06 '17 02:12 tangdf

I'll take a closer look soon and also fix the generic collections with object hashcode problem.

ReubenBond avatar Dec 06 '17 02:12 ReubenBond