Table of Contents

TryGetValueOrFallback Method

Definition

Namespace
Cuemon.Extensions.Collections.Generic
Assemblies
Cuemon.Extensions.Collections.Generic.dll
Source
src/Cuemon.Extensions.Collections.Generic/DictionaryExtensions.cs

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

dictionary IDictionary<TKey, TValue>

The IDictionary<TKey, TValue> to extend.

key TKey

The key of the value to get.

fallbackKeySelector Func<IEnumerable<TKey>, TKey>

The function delegate that will 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

bool

true if the dictionary 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

dictionary cannot be null.