Class DictionaryDecoratorExtensions
- Namespace
- Cuemon.Collections.Generic
- Assembly
- Cuemon.Core.dll
Extension methods for the IDictionary<TKey, TValue> interface hidden behind the IDecorator<T> interface.
public static class DictionaryDecoratorExtensions
- Inheritance
-
DictionaryDecoratorExtensions
Methods
AddOrUpdate<TKey, TValue>(IDecorator<IDictionary<TKey, TValue>>, TKey, TValue)
Attempts to add or update an existing element with the provided key to the enclosed IDictionary<TKey, TValue> of the decorator with the specified value.
public static void AddOrUpdate<TKey, TValue>(this IDecorator<IDictionary<TKey, TValue>> decorator, TKey key, TValue value)
Parameters
decoratorIDecorator<IDictionary<TKey, TValue>>The IDecorator<T> to extend.
keyTKeyThe key of the element to add or update.
valueTValueThe value of the element to add or update.
Type Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
Exceptions
- ArgumentNullException
decoratorcannot be null -or-keycannot be null.
CopyTo<TKey, TValue>(IDecorator<IDictionary<TKey, TValue>>, IDictionary<TKey, TValue>)
Copies all elements from the enclosed IDictionary<TKey, TValue> of decorator to destination.
public static IDictionary<TKey, TValue> CopyTo<TKey, TValue>(this IDecorator<IDictionary<TKey, TValue>> decorator, IDictionary<TKey, TValue> destination)
Parameters
decoratorIDecorator<IDictionary<TKey, TValue>>The IDecorator<T> to extend.
destinationIDictionary<TKey, TValue>The IDictionary<TKey, TValue> to which the elements of the enclosed IDictionary<TKey, TValue> will be copied.
Returns
- IDictionary<TKey, TValue>
An IDictionary<TKey, TValue> that is the result of the populated
destination.
Type Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
CopyTo<TKey, TValue>(IDecorator<IDictionary<TKey, TValue>>, IDictionary<TKey, TValue>, Action<IDictionary<TKey, TValue>, IDictionary<TKey, TValue>>)
Copies elements from the enclosed IDictionary<TKey, TValue> of decorator to destination using the copier delegate.
public static IDictionary<TKey, TValue> CopyTo<TKey, TValue>(this IDecorator<IDictionary<TKey, TValue>> decorator, IDictionary<TKey, TValue> destination, Action<IDictionary<TKey, TValue>, IDictionary<TKey, TValue>> copier)
Parameters
decoratorIDecorator<IDictionary<TKey, TValue>>The IDecorator<T> to extend.
destinationIDictionary<TKey, TValue>The IDictionary<TKey, TValue> to which the elements of the enclosed IDictionary<TKey, TValue> will be copied.
copierAction<IDictionary<TKey, TValue>, IDictionary<TKey, TValue>>The delegate that will populate a copy of the enclosed IDictionary<TKey, TValue> to the specified
destination.
Returns
- IDictionary<TKey, TValue>
An IDictionary<TKey, TValue> that is the result of the populated
destination.
Type Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
GetDepthIndex(IDecorator<IDictionary<int, Dictionary<int, int>>>, int, int, int)
Gets the level of nesting of the enclosed IDictionary<TKey, TValue> of the decorator.
This API supports the product infrastructure and is not intended to be used directly from your code.
public static int GetDepthIndex(this IDecorator<IDictionary<int, Dictionary<int, int>>> decorator, int readerDepth, int index, int nesting)
Parameters
decoratorIDecorator<IDictionary<int, Dictionary<int, int>>>The IDecorator<T> to extend.
readerDepthintThe value that provides the depth of the embedded reader.
indexintThe index to associate with a
nesting.nestingintThe level of nesting.
Returns
- int
The index at the specified
nesting.
GetValueOrDefault<TKey, TValue>(IDecorator<IDictionary<TKey, TValue>>, TKey)
Gets the value associated with the specified key or default when the key does not exists in the enclosed IDictionary<TKey, TValue> of the decorator.
public static TValue GetValueOrDefault<TKey, TValue>(this IDecorator<IDictionary<TKey, TValue>> decorator, TKey key)
Parameters
decoratorIDecorator<IDictionary<TKey, TValue>>The IDecorator<T> to extend.
keyTKeyThe key of the value to get.
Returns
- TValue
Either the value associated with the specified
keyordefault(when the key does not exists.TValue)
Type Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
Exceptions
- ArgumentNullException
decoratorcannot be null -or-keycannot be null.
GetValueOrDefault<TKey, TValue>(IDecorator<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 enclosed IDictionary<TKey, TValue> of the decorator.
public static TValue GetValueOrDefault<TKey, TValue>(this IDecorator<IDictionary<TKey, TValue>> decorator, TKey key, Func<TValue> defaultProvider)
Parameters
decoratorIDecorator<IDictionary<TKey, TValue>>The IDecorator<T> to extend.
keyTKeyThe key of the value to get.
defaultProviderFunc<TValue>The function delegate that will provide a default value when the
keydoes not exists in the enclosed IDictionary<TKey, TValue> of thedecorator.
Returns
- TValue
Either the value associated with the specified
keyor a default value throughdefaultProviderwhen the key does not exists.
Type Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
Exceptions
- ArgumentNullException
decoratorcannot be null -or-keycannot be null -or-defaultProvidercannot be null.
ToEnumerable<TKey, TValue>(IDecorator<IDictionary<TKey, TValue>>)
Returns the enclosed IDictionary<TKey, TValue> of the decorator typed as KeyValuePair<TKey, TValue> sequence.
public static IEnumerable<KeyValuePair<TKey, TValue>> ToEnumerable<TKey, TValue>(this IDecorator<IDictionary<TKey, TValue>> decorator)
Parameters
decoratorIDecorator<IDictionary<TKey, TValue>>The IDecorator<T> to extend.
Returns
- IEnumerable<KeyValuePair<TKey, TValue>>
A KeyValuePair<TKey, TValue> equivalent sequence of the enclosed IDictionary<TKey, TValue> of the
decorator.
Type Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
Exceptions
- ArgumentNullException
decoratorcannot be null.
TryAdd<TKey, TValue>(IDecorator<IDictionary<TKey, TValue>>, TKey, TValue)
Attempts to add the specified key and value to the enclosed IDictionary<TKey, TValue> of the decorator.
public static bool TryAdd<TKey, TValue>(this IDecorator<IDictionary<TKey, TValue>> decorator, TKey key, TValue value)
Parameters
decoratorIDecorator<IDictionary<TKey, TValue>>The IDecorator<T> to extend.
keyTKeyThe key of the element to add.
valueTValueThe value of the element to add.
Returns
- bool
trueif the key/value pair was added to the enclosed IDictionary<TKey, TValue> of thedecoratorsuccessfully; otherwise,false.
Type Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
Exceptions
- ArgumentNullException
decoratorcannot be null -or-keycannot be null.
TryAdd<TKey, TValue>(IDecorator<IDictionary<TKey, TValue>>, TKey, TValue, Func<IDictionary<TKey, TValue>, bool>)
Attempts to add the specified key and value to the enclosed IDictionary<TKey, TValue> of the decorator.
public static bool TryAdd<TKey, TValue>(this IDecorator<IDictionary<TKey, TValue>> decorator, TKey key, TValue value, Func<IDictionary<TKey, TValue>, bool> condition)
Parameters
decoratorIDecorator<IDictionary<TKey, TValue>>The IDecorator<T> to extend.
keyTKeyThe key of the element to add.
valueTValueThe 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 enclosed IDictionary<TKey, TValue> of thedecoratorsuccessfully; otherwise,false.
Type Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
Exceptions
- ArgumentNullException
decoratorcannot be null -or-keycannot be null -or-conditioncannot be null.
TryGetValueOrFallback<TKey, TValue>(IDecorator<IDictionary<TKey, TValue>>, TKey, Func<IEnumerable<TKey>, TKey>, out TValue)
Gets the value associated with the specified key from the enclosed IDictionary<TKey, TValue> of the decorator.
public static bool TryGetValueOrFallback<TKey, TValue>(this IDecorator<IDictionary<TKey, TValue>> decorator, TKey key, Func<IEnumerable<TKey>, TKey> fallbackKeySelector, out TValue value)
Parameters
decoratorIDecorator<IDictionary<TKey, TValue>>The IDecorator<T> to extend.
keyTKeyThe key of the value to get.
fallbackKeySelectorFunc<IEnumerable<TKey>, TKey>The function delegate that will, as a fallback, resolve an alternate key from the specified
key.valueTValueWhen this method returns, contains the value associated with the specified
keyor the alternate key resolved fromfallbackKeySelector, 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 enclosed IDictionary<TKey, TValue> of thedecoratorcontains an element with the specifiedkeyor the alternate key resolved fromfallbackKeySelector,falseotherwise.
Type Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.
Exceptions
- ArgumentNullException
decoratorcannot be null.