Esempio n. 1
0
 public WeakKeyReference(T key, WeakKeyComparer <T> comparer)
     : base(key)
 {
     // retain the object's hash code immediately so that even if the target is GC'ed we will be
     // able to find and remove the dead weak reference.
     HashCode = comparer.GetHashCode(key);
 }
        /// <summary>
        ///A test for GetHashCode
        ///</summary>
        void GetHashCodeTestHelper <E>(E e)
            where E : class
        {
            WeakKeyComparer <E> target = new WeakKeyComparer <E>()
            {
                _equalityComparer = EqualityComparer <E> .Default
            };
            var key = new WeakKey <E>()
            {
                _elementReference = new WeakReference(e)
            };

            int hash1 = target.GetHashCode(ref key, true);

            key.SetValue(e, false);

            int hash2 = target.GetHashCode(ref key, false);

            Assert.AreEqual(hash1, hash2);
        }
Esempio n. 3
0
        public WeakKeyReference(T target, WeakKeyComparer <T> comparer)
            : base(target, false)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            // retain the object's hash code immediately so that even
            // if the target is GC'ed we will be able to find and
            // remove the dead weak reference.
            this.HashCode = comparer.GetHashCode(target);
        }