Collections Collections
Collections Collections
DocFX + Singulink = ♥

Search Results for

    Class WeakValueDictionary<TKey, TValue>

    Represents a collection of keys and weakly referenced values. If this collection is accessed concurrently from multiple threads (even in a read-only manner) then all accesses must be synchronized with a full lock.

    Inheritance
    object
    WeakValueDictionary<TKey, TValue>
    Implements
    IEnumerable<KeyValuePair<TKey, TValue>>
    IEnumerable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Singulink.Collections
    Assembly: Singulink.Collections.Weak.dll
    Syntax
    public class WeakValueDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable where TKey : notnull where TValue : class
    Type Parameters
    Name Description
    TKey Represents a collection of keys and weakly referenced values. If this collection is accessed concurrently from multiple threads (even in a read-only manner) then all accesses must be synchronized with a full lock.
    TValue Represents a collection of keys and weakly referenced values. If this collection is accessed concurrently from multiple threads (even in a read-only manner) then all accesses must be synchronized with a full lock.
    Remarks

    On .NET, internal entries for garbage collected values are cleaned as they are encountered (i.e. when a key lookup is performed on a garbage collected value or key/value pairs are enumerated over). This is not the case on .NET Standard targets like .NET Framework. You can perform a full clean by calling the Clean() method or configure automatic cleaning after a set number of add operations by setting the AutoCleanAddCount property.

    Constructors

    Name Description
    WeakValueDictionary()

    Initializes a new instance of the WeakValueDictionary<TKey, TValue> class.

    WeakValueDictionary(IEqualityComparer<TKey>?)

    Initializes a new instance of the WeakValueDictionary<TKey, TValue> class using the specified key equality comparer.

    Properties

    Name Description
    AddCountSinceLastClean

    Gets the number of add (or indexer set) operations that have been performed since the last cleaning.

    AutoCleanAddCount

    Gets or sets the number of add (or indexer set) operations that automatically triggers the Clean() method to run. Default value is null which indicates that automatic cleaning is not performed.

    this[TKey]

    Gets or sets the value associated with the specified key.

    Keys

    Gets the keys in the dictionary.

    TrimExcessDuringClean

    Gets or sets a value indicating whether to automatically call TrimExcess() whenever Clean() is called. Default value is false.

    UnsafeCount

    Gets the number of entries in the internal data structure. This value will be different than the actual count if any of the values were garbage collected but still have internal entries in the dictionary that have not been cleaned.

    Values

    Gets the values in the dictionary.

    Methods

    Name Description
    Add(TKey, TValue)

    Adds the specified key and value to the dictionary.

    Clean()

    Removes internal entries that refer to values that have been garbage collected.

    Clear()

    Removes all keys and values from the dictionary.

    Contains(KeyValuePair<TKey, TValue>, IEqualityComparer<TValue>?)

    Indictes whether the dictionary contains the specified key/value pair using the optionally specified value comparer.

    Contains(TKey, TValue, IEqualityComparer<TValue>?)

    Indictes whether the dictionary contains the key and value using the optionally specified value comparer.

    ContainsKey(TKey)

    Determines whether the dictionary contains the specified key.

    ContainsValue(TValue, IEqualityComparer<TValue>?)

    Determines whether the dictionary contains the specified value.

    EnsureCapacity(int)

    Ensures that this dictionary can hold the specified number of elements without growing.

    GetEnumerator()

    Returns an enumerator that iterates through the key/value pairs in the dictionary.

    Remove(TKey)

    Removes the value with the specified key from the dictionary.

    Remove(TKey, TValue, IEqualityComparer<TValue>?)

    Removes the entry with the given key and value from the dictionary using the specified equality comparer for the value type.

    Remove(TKey, out TValue)

    Removes the value with the specified key from the dictionary.

    TrimExcess()

    Reduces the internal capacity of this dictionary to the size needed to hold the current entries.

    TryAdd(TKey, TValue)

    Adds the specified key and value to the dictionary.

    TryGetValue(TKey, out TValue?)

    Gets the value associated with the specified key.

    Explicit Interface Implementations

    Name Description
    IEnumerable.GetEnumerator()

    Returns an enumerator that iterates through the key/value pairs in the dictionary.

    © Singulink. All rights reserved.