예제 #1
0
            public override bool Equals(object obj)
            {
                SimpleObjectWithOverridenEquals o = obj as SimpleObjectWithOverridenEquals;

                if (o == null)
                {
                    return(false);
                }

                return(A == o.A);
            }
예제 #2
0
        public void HashSetOfObjectsSimpleObjectWithOverridenEqualsButWithAReferenceEqualityComparerTest()
        {
            // Create an object and add it to the hash set
            SimpleObjectWithOverridenEquals obj = new SimpleObjectWithOverridenEquals
            {
                A = 2
            };

            HashSet <object> hs = new HashSet <object>(ReferenceComparer.Instance);

            hs.Add(obj);

            Assert.IsTrue(hs.Contains(obj));

            // Modify the object
            obj.A = 33;

            Assert.IsTrue(hs.Contains(obj)); // Modified objects will have a different hash code, but they are still found
        }
예제 #3
0
        public void HashSetOfObjectsSimpleObjectWithOverridenEqualsTest()
        {
            // Create an object and add it to the hash set
            SimpleObjectWithOverridenEquals obj = new SimpleObjectWithOverridenEquals
            {
                A = 2
            };

            HashSet <object> hs = new HashSet <object>();

            hs.Add(obj);

            Assert.IsTrue(hs.Contains(obj));

            // Modify the object
            obj.A = 33;

            Assert.IsFalse(hs.Contains(obj)); // Modified objects will have a different hash code
        }