Example #1
0
        public int GetHashCode(object obj)
        {
            WeakKeyReference <T> weakKey = obj as WeakKeyReference <T>;

            if (weakKey != null)
            {
                return(weakKey.HashCode);
            }
            return(this.comparer.GetHashCode((T)obj));
        }
Example #2
0
        public override void Add(TKey key, TValue value)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            WeakReference <TKey>   weakKey   = new WeakKeyReference <TKey>(key, this.comparer);
            WeakReference <TValue> weakValue = WeakReference <TValue> .Create(value);

            this.dictionary.Add(weakKey, weakValue);
        }
Example #3
0
        private static T GetTarget(object obj, out bool isDead)
        {
            WeakKeyReference <T> wref = obj as WeakKeyReference <T>;
            T target;

            if (wref != null)
            {
                target = wref.Target;
                isDead = !wref.IsAlive;
            }
            else
            {
                target = (T)obj;
                isDead = false;
            }
            return(target);
        }
Example #4
0
        protected override void SetValue(TKey key, TValue value)
        {
            WeakReference <TKey> weakKey = new WeakKeyReference <TKey>(key, this.comparer);

            this.dictionary[weakKey] = WeakReference <TValue> .Create(value);
        }