예제 #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));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }