/// <summary> /// Adds an element with the provided key and value to the <see cref="T:System.Collections.Generic.IDictionary`2"/>. /// </summary> /// <param name="key">The object to use as the key of the element to add.</param> /// <param name="value">The object to use as the value of the element to add.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key"/> is null.</exception> /// <exception cref="T:System.ArgumentException">An element with the same key already exists in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.</exception> /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only.</exception> public override void Add(TKey key, TValue value) { if (key == null) { throw new ArgumentNullException("key"); } var weakKey = new WeakKeyReference <TKey>(key, comparer); dictionary.Add(weakKey, value); }
/// <summary> /// Sets the value. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> protected override void SetValue(TKey key, TValue value) { WeakReference <TKey> weakKey = new WeakKeyReference <TKey>(key, comparer); dictionary[weakKey] = value; }