Table of Contents

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

decorator IDecorator<IDictionary<TKey, TValue>>

The IDecorator<T> to extend.

key TKey

The key of the element to add or update.

value TValue

The value of the element to add or update.

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Exceptions

ArgumentNullException

decorator cannot be null -or- key cannot 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

decorator IDecorator<IDictionary<TKey, TValue>>

The IDecorator<T> to extend.

destination IDictionary<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

TKey

The type of the keys in the dictionary.

TValue

The 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

decorator IDecorator<IDictionary<TKey, TValue>>

The IDecorator<T> to extend.

destination IDictionary<TKey, TValue>

The IDictionary<TKey,TValue> to which the elements of the enclosed IDictionary<TKey,TValue> will be copied.

copier Action<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

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

GetDepthIndex(IDecorator<IDictionary<Int32, Dictionary<Int32, Int32>>>, Int32, Int32, Int32)

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

decorator IDecorator<IDictionary<Int32, Dictionary<Int32, Int32>>>

The IDecorator<T> to extend.

readerDepth Int32

The value that provides the depth of the embedded reader.

index Int32

The index to associate with a nesting.

nesting Int32

The level of nesting.

Returns

Int32

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

decorator IDecorator<IDictionary<TKey, TValue>>

The IDecorator<T> to extend.

key TKey

The key of the value to get.

Returns

TValue

Either the value associated with the specified key or default(TValue) when 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

decorator cannot be null -or- key cannot 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

decorator IDecorator<IDictionary<TKey, TValue>>

The IDecorator<T> to extend.

key TKey

The key of the value to get.

defaultProvider Func<TValue>

The function delegate that will provide a default value when the key does not exists in the enclosed IDictionary<TKey,TValue> of the decorator.

Returns

TValue

Either the value associated with the specified key or a default value through defaultProvider when 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

decorator cannot be null -or- key cannot be null -or- defaultProvider cannot 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

decorator IDecorator<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

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Exceptions

ArgumentNullException

decorator cannot 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

decorator IDecorator<IDictionary<TKey, TValue>>

The IDecorator<T> to extend.

key TKey

The key of the element to add.

value TValue

The value of the element to add.

Returns

Boolean

true if the key/value pair was added to the enclosed IDictionary<TKey,TValue> of the decorator successfully; otherwise, false.

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Exceptions

ArgumentNullException

decorator cannot be null -or- key cannot be null.

TryAdd<TKey, TValue>(IDecorator<IDictionary<TKey, TValue>>, TKey, TValue, Func<IDictionary<TKey, TValue>, Boolean>)

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

decorator IDecorator<IDictionary<TKey, TValue>>

The IDecorator<T> to extend.

key TKey

The key of the element to add.

value TValue

The value of the element to add.

condition Func<IDictionary<TKey, TValue>, Boolean>

The function delegate that specifies the condition for adding the element.

Returns

Boolean

true if the key/value pair was added to the enclosed IDictionary<TKey,TValue> of the decorator successfully; otherwise, false.

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Exceptions

ArgumentNullException

decorator cannot be null -or- key cannot be null -or- condition cannot 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

decorator IDecorator<IDictionary<TKey, TValue>>

The IDecorator<T> to extend.

key TKey

The key of the value to get.

fallbackKeySelector Func<IEnumerable<TKey>, TKey>

The function delegate that will, as a fallback, resolve an alternate key from the specified key.

value TValue

When this method returns, contains the value associated with the specified key or 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

Boolean

true if the enclosed IDictionary<TKey,TValue> of the decorator contains an element with the specified key or the alternate key resolved from fallbackKeySelector, false otherwise.

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Exceptions

ArgumentNullException

decorator cannot be null.

See Also