Class DictionaryExtensions
- Namespace
- Cuemon.Extensions.Collections.Generic
- Assembly
- Cuemon.Extensions.Collections.Generic.dll
Extension methods for the IDictionary<TKey, TValue> interface.
public static class DictionaryExtensions- Inheritance
- 
      
      DictionaryExtensions
Methods
AddOrUpdate<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue)
Attempts to add or update an existing element with the provided key to the dictionary with the specified value.
public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)Parameters
- dictionaryIDictionary<TKey, TValue>
- The IDictionary<TKey, TValue> to extend. 
- keyTKey
- The key of the element to add or update. 
- valueTValue
- The value of the element to add or update. 
Type Parameters
- TKey
- TValue
Exceptions
- ArgumentNullException
- dictionarycannot be null -or-- keycannot be null.
CopyTo<TKey, TValue>(IDictionary<TKey, TValue>, IDictionary<TKey, TValue>)
Copies all elements from source to destination.
public static IDictionary<TKey, TValue> CopyTo<TKey, TValue>(this IDictionary<TKey, TValue> source, IDictionary<TKey, TValue> destination)Parameters
- sourceIDictionary<TKey, TValue>
- The IDictionary<TKey, TValue> to extend. 
- destinationIDictionary<TKey, TValue>
- The IDictionary<TKey, TValue> to which the elements of the - sourcewill be copied.
Returns
- IDictionary<TKey, TValue>
- An IDictionary<TKey, TValue> that is the result of the populated - destination.
Type Parameters
- TKey
- The type of the keys in the dictionary. 
- TValue
- The type of the values in the dictionary. 
CopyTo<TKey, TValue>(IDictionary<TKey, TValue>, IDictionary<TKey, TValue>, Action<IDictionary<TKey, TValue>, IDictionary<TKey, TValue>>)
Copies elements from source to destination using the copier delegate.
public static IDictionary<TKey, TValue> CopyTo<TKey, TValue>(this IDictionary<TKey, TValue> source, IDictionary<TKey, TValue> destination, Action<IDictionary<TKey, TValue>, IDictionary<TKey, TValue>> copier)Parameters
- sourceIDictionary<TKey, TValue>
- The IDictionary<TKey, TValue> to extend. 
- destinationIDictionary<TKey, TValue>
- The IDictionary<TKey, TValue> to which the elements of the - sourcewill be copied.
- copierAction<IDictionary<TKey, TValue>, IDictionary<TKey, TValue>>
- The delegate that will populate a copy of - sourceto the specified- destination.
Returns
- IDictionary<TKey, TValue>
- An IDictionary<TKey, TValue> that is the result of the populated - destination.
Type Parameters
- TKey
- The type of the keys in the dictionary. 
- TValue
- The type of the values in the dictionary. 
GetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue>, TKey, Func<TValue>)
Gets the value associated with the specified key or a default value through defaultProvider when the key does not exists in the dictionary.
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TValue> defaultProvider)Parameters
- dictionaryIDictionary<TKey, TValue>
- The IDictionary<TKey, TValue> to extend. 
- keyTKey
- The key of the value to get. 
- defaultProviderFunc<TValue>
- The function delegate that will provide a default value when the - keydoes not exists in the- dictionary.
Returns
- TValue
- Either the value associated with the specified - keyor a default value through- defaultProviderwhen the key does not exists.
Type Parameters
- TKey
- The type of the keys in the - dictionary.
- TValue
- The type of the values in the - dictionary.
Exceptions
- ArgumentNullException
- dictionarycannot be null -or-- keycannot be null -or-- defaultProvidercannot be null.
ToEnumerable<TKey, TValue>(IDictionary<TKey, TValue>)
Returns the specified dictionary typed as KeyValuePair<TKey, TValue> sequence.
public static IEnumerable<KeyValuePair<TKey, TValue>> ToEnumerable<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)Parameters
- dictionaryIDictionary<TKey, TValue>
- The IDictionary<TKey, TValue> to extend. 
Returns
- IEnumerable<KeyValuePair<TKey, TValue>>
- A KeyValuePair<TKey, TValue> equivalent sequence of - dictionary.
Type Parameters
- TKey
- The Type of the key in the resulting KeyValuePair<TKey, TValue>. 
- TValue
- The Type of the value in the resulting KeyValuePair<TKey, TValue>. 
Exceptions
- ArgumentNullException
- dictionaryis null.
TryAdd<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue, Func<IDictionary<TKey, TValue>, bool>)
Attempts to add the specified key and value to the dictionary.
public static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value, Func<IDictionary<TKey, TValue>, bool> condition)Parameters
- dictionaryIDictionary<TKey, TValue>
- The IDictionary<TKey, TValue> to extend. 
- keyTKey
- The key of the element to add. 
- valueTValue
- The value of the element to add. 
- conditionFunc<IDictionary<TKey, TValue>, bool>
- The function delegate that specifies the condition for adding the element. 
Returns
- bool
- trueif the key/value pair was added to the- dictionarysuccessfully; otherwise,- false.
Type Parameters
- TKey
- TValue
Exceptions
- ArgumentNullException
- dictionarycannot be null -or-- keycannot be null -or-- conditioncannot be null.
TryGetValueOrFallback<TKey, TValue>(IDictionary<TKey, TValue>, TKey, Func<IEnumerable<TKey>, TKey>, out TValue)
Gets the value associated with the specified key.
public static bool TryGetValueOrFallback<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<IEnumerable<TKey>, TKey> fallbackKeySelector, out TValue value)Parameters
- dictionaryIDictionary<TKey, TValue>
- The IDictionary<TKey, TValue> to extend. 
- keyTKey
- The key of the value to get. 
- fallbackKeySelectorFunc<IEnumerable<TKey>, TKey>
- The function delegate that will resolve an alternate key from the specified - key.
- valueTValue
- When this method returns, contains the value associated with the specified - keyor the alternate key resolved from- fallbackKeySelector, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
Returns
- bool
- trueif the- dictionarycontains an element with the specified- keyor the alternate key resolved from- fallbackKeySelector,- falseotherwise.
Type Parameters
- TKey
- The type of the keys in the - dictionary.
- TValue
- The type of the values in the - dictionary.
Exceptions
- ArgumentNullException
- dictionarycannot be null.