Class Dictionary
Represents various extensions for types
Namespace: DotNext.Collections.Generic
Assembly: DotNext.dll
Syntax
public static class Dictionary : object
Methods
| Improve this Doc View SourceConvertValues<K, V, T>(IReadOnlyDictionary<K, V>, Converter<V, T>)
Applies lazy conversion for each dictionary value.
Declaration
public static ReadOnlyDictionaryView<K, V, T> ConvertValues<K, V, T>(this IReadOnlyDictionary<K, V> dictionary, Converter<V, T> mapper)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyDictionary<K, V> | dictionary | A dictionary to be mapped. |
DotNext.Converter<V, T> | mapper | Mapping function. |
Returns
Type | Description |
---|---|
ReadOnlyDictionaryView<K, V, T> | Read-only view of the dictionary where each value is converted in lazy manner. |
Type Parameters
Name | Description |
---|---|
K | Type of keys. |
V | Type of values. |
T | Type of mapped values. |
ConvertValues<K, V, T>(IReadOnlyDictionary<K, V>, ValueFunc<V, T>)
Applies lazy conversion for each dictionary value.
Declaration
public static ReadOnlyDictionaryView<K, V, T> ConvertValues<K, V, T>(this IReadOnlyDictionary<K, V> dictionary, in ValueFunc<V, T> mapper)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyDictionary<K, V> | dictionary | A dictionary to be mapped. |
ValueFunc<V, T> | mapper | Mapping function. |
Returns
Type | Description |
---|---|
ReadOnlyDictionaryView<K, V, T> | Read-only view of the dictionary where each value is converted in lazy manner. |
Type Parameters
Name | Description |
---|---|
K | Type of keys. |
V | Type of values. |
T | Type of mapped values. |
Deconstruct<K, V>(KeyValuePair<K, V>, out K, out V)
Deconstruct key/value pair.
Declaration
public static void Deconstruct<K, V>(this KeyValuePair<K, V> pair, out K key, out V value)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<K, V> | pair | A pair to decompose. |
K | key | Deconstructed key. |
V | value | Deconstructed value. |
Type Parameters
Name | Description |
---|---|
K | Type of key. |
V | Type of value. |
ForEach<K, V>(IDictionary<K, V>, Action<K, V>)
Applies specific action to each dictionary
Declaration
public static void ForEach<K, V>(this IDictionary<K, V> dictionary, Action<K, V> action)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<K, V> | dictionary | A dictionary to read from. |
Action<K, V> | action | The action to be applied for each key/value pair. |
Type Parameters
Name | Description |
---|---|
K | The key type of the dictionary. |
V | The value type of the dictionary. |
ForEach<K, V>(IDictionary<K, V>, ValueAction<K, V>)
Applies specific action to each dictionary
Declaration
public static void ForEach<K, V>(this IDictionary<K, V> dictionary, in ValueAction<K, V> action)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<K, V> | dictionary | A dictionary to read from. |
ValueAction<K, V> | action | The action to be applied for each key/value pair. |
Type Parameters
Name | Description |
---|---|
K | The key type of the dictionary. |
V | The value type of the dictionary. |
GetOrAdd<K, V>(Dictionary<K, V>, K)
Adds a key-value pair to the dictionary if the key does not exist.
Declaration
public static V GetOrAdd<K, V>(this Dictionary<K, V> dictionary, K key)
where V : new()
Parameters
Type | Name | Description |
---|---|---|
DotNext.Collections.Generic.Dictionary<K, V> | dictionary | The source dictionary. |
K | key | The key of the key-value pair. |
Returns
Type | Description |
---|---|
V | The corresponding value in the dictionary if |
Type Parameters
Name | Description |
---|---|
K | The key type of the dictionary. |
V | The value type of the dictionary. |
GetOrAdd<K, V>(Dictionary<K, V>, K, V)
Adds a key-value pair to the dictionary if the key does not exist.
Declaration
public static V GetOrAdd<K, V>(this Dictionary<K, V> dictionary, K key, V value)
Parameters
Type | Name | Description |
---|---|---|
DotNext.Collections.Generic.Dictionary<K, V> | dictionary | The source dictionary. |
K | key | The key of the key-value pair. |
V | value | The value of the key-value pair. |
Returns
Type | Description |
---|---|
V | The corresponding value in the dictionary if |
Type Parameters
Name | Description |
---|---|
K | The key type of the dictionary. |
V | The value type of the dictionary. |
GetOrAdd<K, V>(Dictionary<K, V>, K, Func<K, V>)
Generates a value and adds the key-value pair to the dictionary if the key does not exist.
Declaration
public static V GetOrAdd<K, V>(this Dictionary<K, V> dictionary, K key, Func<K, V> valueFactory)
Parameters
Type | Name | Description |
---|---|---|
DotNext.Collections.Generic.Dictionary<K, V> | dictionary | The source dictionary. |
K | key | The key of the key-value pair. |
DotNext.Func<K, V> | valueFactory | The function used to generate the value from the key. |
Returns
Type | Description |
---|---|
V | The corresponding value in the dictionary if |
Type Parameters
Name | Description |
---|---|
K | The key type of the dictionary. |
V | The value type of the dictionary. |
GetOrAdd<K, V>(Dictionary<K, V>, K, ValueFunc<K, V>)
Generates a value and adds the key-value pair to the dictionary if the key does not exist.
Declaration
public static V GetOrAdd<K, V>(this Dictionary<K, V> dictionary, K key, in ValueFunc<K, V> valueFactory)
Parameters
Type | Name | Description |
---|---|---|
DotNext.Collections.Generic.Dictionary<K, V> | dictionary | The source dictionary. |
K | key | The key of the key-value pair. |
ValueFunc<K, V> | valueFactory | The function used to generate the value from the key. |
Returns
Type | Description |
---|---|
V | The corresponding value in the dictionary if |
Type Parameters
Name | Description |
---|---|
K | The key type of the dictionary. |
V | The value type of the dictionary. |
GetOrInvoke<K, V>(IDictionary<K, V>, K, Func<V>)
Gets dictionary value by key if it exists or
invoke defaultValue
and
return its result as a default value.
Declaration
public static V GetOrInvoke<K, V>(this IDictionary<K, V> dictionary, K key, Func<V> defaultValue)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<K, V> | dictionary | A dictionary to read from. |
K | key | A key associated with the value. |
DotNext.Func<V> | defaultValue | A delegate to be invoked if key doesn't exist in the dictionary. |
Returns
Type | Description |
---|---|
V | The value associated with the key or returned by the delegate. |
Type Parameters
Name | Description |
---|---|
K | Type of dictionary keys. |
V | Type of dictionary values. |
GetOrInvoke<K, V>(IDictionary<K, V>, K, ValueFunc<V>)
Gets dictionary value by key if it exists or
invoke defaultValue
and
return its result as a default value.
Declaration
public static V GetOrInvoke<K, V>(this IDictionary<K, V> dictionary, K key, in ValueFunc<V> defaultValue)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<K, V> | dictionary | A dictionary to read from. |
K | key | A key associated with the value. |
ValueFunc<V> | defaultValue | A delegate to be invoked if key doesn't exist in the dictionary. |
Returns
Type | Description |
---|---|
V | The value associated with the key or returned by the delegate. |
Type Parameters
Name | Description |
---|---|
K | Type of dictionary keys. |
V | Type of dictionary values. |
IndexerGetter<K, V>(IDictionary<K, V>)
Returns
Declaration
public static Func<K, V> IndexerGetter<K, V>(this IDictionary<K, V> dictionary)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<K, V> | dictionary | Mutable dictionary instance. |
Returns
Type | Description |
---|---|
DotNext.Func<K, V> | A delegate representing dictionary indexer. |
Type Parameters
Name | Description |
---|---|
K | Type of dictionary keys. |
V | Type of dictionary values. |
IndexerGetter<K, V>(IReadOnlyDictionary<K, V>)
Returns
Declaration
public static Func<K, V> IndexerGetter<K, V>(this IReadOnlyDictionary<K, V> dictionary)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyDictionary<K, V> | dictionary | Read-only dictionary instance. |
Returns
Type | Description |
---|---|
DotNext.Func<K, V> | A delegate representing dictionary indexer. |
Type Parameters
Name | Description |
---|---|
K | Type of dictionary keys. |
V | Type of dictionary values. |
IndexerSetter<K, V>(IDictionary<K, V>)
Returns
Declaration
public static Action<K, V> IndexerSetter<K, V>(this IDictionary<K, V> dictionary)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<K, V> | dictionary | Mutable dictionary instance. |
Returns
Type | Description |
---|---|
Action<K, V> | A delegate representing dictionary indexer. |
Type Parameters
Name | Description |
---|---|
K | Type of dictionary keys. |
V | Type of dictionary values. |
TryGetValue<K, V>(IDictionary<K, V>, K)
Gets the value associated with the specified key.
Declaration
public static Optional<V> TryGetValue<K, V>(this IDictionary<K, V> dictionary, K key)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<K, V> | dictionary | A dictionary to read from. |
K | key | The key whose value to get. |
Returns
Type | Description |
---|---|
Optional<V> | The optional value associated with the key. |
Type Parameters
Name | Description |
---|---|
K | Type of dictionary keys. |
V | Type of dictionary values. |
TryGetValue<K, V>(IReadOnlyDictionary<K, V>, K)
Gets the value associated with the specified key.
Declaration
public static Optional<V> TryGetValue<K, V>(IReadOnlyDictionary<K, V> dictionary, K key)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyDictionary<K, V> | dictionary | A dictionary to read from. |
K | key | The key whose value to get. |
Returns
Type | Description |
---|---|
Optional<V> | The optional value associated with the key. |
Type Parameters
Name | Description |
---|---|
K | Type of dictionary keys. |
V | Type of dictionary values. |
TryRemove<K, V>(IDictionary<K, V>, K)
Removes the value with the specified key and return the removed value.
Declaration
public static Optional<V> TryRemove<K, V>(this IDictionary<K, V> dictionary, K key)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<K, V> | dictionary | A dictionary to modify. |
K | key | The key of the element to remove. |
Returns
Type | Description |
---|---|
Optional<V> | The removed value. |
Type Parameters
Name | Description |
---|---|
K | Type of dictionary keys. |
V | Type of dictionary values. |