DeepCopy icon indicating copy to clipboard operation
DeepCopy copied to clipboard

A problem of HashSet<>

Open tangdf opened this issue 8 years ago • 2 comments

        private class MyClass
        {
            
        }
        [Fact]
        public void CopyObjectHashSet()
        {
            HashSet<MyClass> original = new HashSet<MyClass>();
            original.Add(new MyClass());

            var result = DeepCopier.Copy(original);

            Assert.NotSame(original, result);
            foreach (MyClass myClass in result) {
                Assert.True(result.Contains(myClass));
            }
        }

After deep copy , then Contains method return false.

tangdf avatar Nov 08 '17 02:11 tangdf

We'll have to add custom copiers in order to make this work - the hash code for each object is stored in the HashTable.

ReubenBond avatar Nov 09 '17 06:11 ReubenBond