public override void Add(TKey key, TValue value)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            WeakReference <TKey> weakKey = new WeakKeyReference <TKey>(key, this.comparer);

            this.dictionary.Add(weakKey, value);
        }
示例#2
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));
        }
示例#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);
        }
        protected override void SetValue(TKey key, TValue value)
        {
            WeakReference <TKey> weakKey = new WeakKeyReference <TKey>(key, this.comparer);

            this.dictionary[weakKey] = value;
        }