DictionaryExtensions Class

Provides extension methods for the IDictionaryTKey, TValue type.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static class DictionaryExtensions
Inheritance
Object    DictionaryExtensions

Methods

AddOrUpdateTKey, TValue(IDictionaryTKey, TValue, TKey, TValue, TValue) Adds or updates a key/value pair in the dictionary based on whether the specified key already exists. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.
AddOrUpdateTKey, TValue(IDictionaryTKey, TValue, TKey, TValue, FuncTKey, TValue, TValue) Adds a key/value pair to the dictionary if the key does not already exist, or updates a key/value pair in the dictionary by using the specified updateValueFactory if the key already exists. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.
AddOrUpdateTKey, TValue(IDictionaryTKey, TValue, TKey, FuncTKey, TValue, FuncTKey, TValue, TValue) Uses the specified delegates to add a key/value pair to the dictionary if the key does not already exist, or to update a key/value pair in the dictionary if the key already exists. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.
AddOrUpdateTKey, TValue, TArg(IDictionaryTKey, TValue, TKey, FuncTKey, TArg, TValue, FuncTKey, TValue, TArg, TValue, TArg) Uses the specified delegates to add a key/value pair to the dictionary if the key does not already exist, or to update a key/value pair in the dictionary if the key already exists. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.
AsThreadSafeTKey, TValue Returns a LockingDictionaryTKey, TValue, which provides a thread-safe wrapper for the specified dictionary. This only means that if the members are accessed through the returned LockingDictionaryTKey, TValue, then the inner state of the wrapped dictionary remains always consistent and not that all of the multi-threading concerns can be ignored.
See the Remarks section of the LockingDictionaryTKey, TValue class for details and some examples.
GetActualValueOrDefaultTKey, TValue, TActualValue(IDictionaryTKey, TValue, TKey, TActualValue) Tries to get the typed value from a dictionary for the given key. In this method defaultValue can have a different type than TValue.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetActualValueOrDefaultTKey, TValue, TActualValue(IDictionaryTKey, TValue, TKey, FuncTActualValue) Tries to get the typed value from a dictionary for the given key. In this method defaultValueFactory can return an instance of a different type than TValue.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetActualValueOrDefaultTKey, TValue, TActualValue(IEnumerableKeyValuePairTKey, TValue, TKey, TActualValue) Tries to get the typed value from a dictionary for the given key. Unlike in the GetValueOrDefaultTKey, TValue(IEnumerableKeyValuePairTKey, TValue, TKey, TValue) overload, here defaultValue can have a different type than TValue.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetActualValueOrDefaultTKey, TValue, TActualValue(IEnumerableKeyValuePairTKey, TValue, TKey, FuncTActualValue) Tries to get the typed value from a dictionary for the given key. Unlike in the GetValueOrDefaultTKey, TValue(IEnumerableKeyValuePairTKey, TValue, TKey, FuncTValue) overload, here defaultValueFactory can return an instance of a different type than TValue.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetOrAddTKey, TValue(IDictionaryTKey, TValue, TKey, TValue) Adds a key/value pair to the dictionary if the key does not already exist, and returns either the added or the existing value. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.
GetOrAddTKey, TValue(IDictionaryTKey, TValue, TKey, FuncTKey, TValue) Adds a key/value pair to the dictionary by using the specified addValueFactory if the key does not already exist, and returns either the added or the existing value. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.
GetOrAddTKey, TValue, TArg(IDictionaryTKey, TValue, TKey, FuncTKey, TArg, TValue, TArg) Adds a key/value pair to the dictionary by using the specified addValueFactory if the key does not already exist, and returns either the added or the existing value. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.
GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) Tries to get the typed value from a string-object dictionary for the given key.
GetValueOrDefaultTActualValue(IEnumerableKeyValuePairString, Object, String, TActualValue) Tries to get the typed value from a string-object dictionary for the given key.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetValueOrDefaultTKey, TValue(IDictionaryTKey, TValue, TKey) Tries to get a value from a dictionary for the given key.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetValueOrDefaultTKey, TValue(IEnumerableKeyValuePairTKey, TValue, TKey) Tries to get a value from the provided dictionary for the given key.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetValueOrDefaultTKey, TValue(IDictionaryTKey, TValue, TKey, TValue) Tries to get a value from a dictionary for the given key.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetValueOrDefaultTKey, TValue(IDictionaryTKey, TValue, TKey, FuncTValue) Tries to get a value from a dictionary for the given key.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetValueOrDefaultTKey, TValue(IEnumerableKeyValuePairTKey, TValue, TKey, TValue) Tries to get a value from the provided dictionary for the given key.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
GetValueOrDefaultTKey, TValue(IEnumerableKeyValuePairTKey, TValue, TKey, FuncTValue) Tries to get a value from the provided dictionary for the given key.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.
TryAddTKey, TValue Tries to add a pair of key and value the specified dictionary. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.
TryRemoveTKey, TValue(IDictionaryTKey, TValue, TKey) Tries to remove the value with the specified key from the specified dictionary.
TryRemoveTKey, TValue(IDictionaryTKey, TValue, TKey, TValue) Tries to remove and return the value with the specified key from the specified dictionary. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.
TryUpdateTKey, TValue Tries to update the value associated with key to newValue if the existing value with key is equal to originalValue. The operation is thread safe if dictionary is a ThreadSafeDictionaryTKey, TValue, ConcurrentDictionaryTKey, TValue or LockingDictionaryTKey, TValue instance. For other IDictionaryTKey, TValue implementations the caller should care about thread safety if needed.

See Also