Exemplo n.º 1
0
        /// <summary>
        /// The constructor with a specified comparer and a referesh interval.
        /// </summary>
        /// <param name="comparer">
        /// The IEqualityComparer used to determine equals of object of <typeparamref name="TKey"/>.
        /// </param>
        /// <param name="refreshInterval">
        /// The interval for calling RemoveCollectedEntries to refresh the dictionary.
        /// </param>
        public WeakDictionary(IEqualityComparer <TKey> comparer, int refreshInterval)
        {
            this.comparer = comparer as WeakKeyComparer <TKey>;
            if (this.comparer == null)
            {
                this.comparer = new WeakKeyComparer <TKey>(comparer);
            }

            this.dictionary           = new Dictionary <object, TValue>(this.comparer);
            this.intervalForRefresh   = refreshInterval;
            this.countLimitForRefresh = refreshInterval;
        }
Exemplo n.º 2
0
        public WeakKeyReference(T target, WeakKeyComparer <T> comparer)
            : base(target, false)
        {
            if (target == null)
            {
                throw new ArgumentNullException("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);
        }