Class DictionaryUtilityExtensions
This is an extension implementation of the most common methods on the DictionaryUtility class.
Inheritance
Namespace: Cuemon.Collections.Generic
Assembly: Cuemon.Core.dll
Syntax
public static class DictionaryUtilityExtensions
Methods
| Improve this DocAddIfNotContainsKey<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue)
Adds an element with the provided key and value to the System.Collections.Generic.IDictionary<TKey, TValue>, if the key is not contained within the source.
Declaration
public static void AddIfNotContainsKey<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IDictionary<TKey, TValue> | source | The System.Collections.Generic.IDictionary<TKey, TValue> to perform the operation. |
| TKey | key | The object to use as the key of the element to add. |
| TValue | value | The object to use as the value of the element to add. |
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of keys in the dictionary. |
| TValue | The type of values in the dictionary. |
AddOrUpdate<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue)
Adds or updates an existing element with the provided key in the System.Collections.Generic.IDictionary<TKey, TValue> with the specified value.
Declaration
public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IDictionary<TKey, TValue> | source | The System.Collections.Generic.IDictionary<TKey, TValue> to perform the operation. |
| TKey | key | The object to use as the key of the element to add. |
| TValue | value | The object to use as the value of the element to add or update. |
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of keys in the dictionary. |
| TValue | The type of values in the dictionary. |
FirstMatchOrDefault<TKey, TValue>(IDictionary<TKey, TValue>, TKey[])
Returns the first TValue matching one of the specified keys in a System.Collections.Generic.IDictionary<TKey, TValue>, or a default value if the source contains no elements or no match was found.
Declaration
public static TValue FirstMatchOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> source, params TKey[] keys)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IDictionary<TKey, TValue> | source | The System.Collections.Generic.IDictionary<TKey, TValue> to return a matching |
| TKey[] | keys | A variable number of keys to match in the specified |
Returns
| Type | Description |
|---|---|
| TValue | default(TValue) if source is empty or no match was found; otherwise, the matching element in |
Type Parameters
| Name | Description |
|---|---|
| TKey | The System.Type of the key. |
| TValue | The System.Type of the value. |
Remarks
The default value for reference and nullable types is null.