Table of Contents

TryAdd Method

Definition

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

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>, bool>

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

Returns

bool

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.

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

bool

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.