Table of Contents

GetValueOrDefault Method

Definition

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.