Table of Contents

Class DictionaryUtil

Namespace
Hi.Common.Collections
Assembly
HiGeom.dll

Utility class providing extension methods for dictionary operations.

public static class DictionaryUtil
Inheritance
DictionaryUtil
Inherited Members

Methods

Retrieve<K, V>(Dictionary<K, V>, K, out V, bool)

Retrieves a value from a dictionary by key, with an option to remove it from the source.

public static bool Retrieve<K, V>(this Dictionary<K, V> src, K key, out V v, bool removeFromSource)

Parameters

src Dictionary<K, V>

The source dictionary.

key K

The key to look for.

v V

When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.

removeFromSource bool

If true, removes the key-value pair from the dictionary if found.

Returns

bool

true if the key was found; otherwise, false.

Type Parameters

K

The type of the keys in the dictionary.

V

The type of the values in the dictionary.

TryGetValueByKeys<TKey, TValue>(IDictionary<TKey, TValue>, IEnumerable<TKey>, out TValue)

Tries to get a value from a dictionary by checking multiple keys in sequence.

public static bool TryGetValueByKeys<TKey, TValue>(this IDictionary<TKey, TValue> src, IEnumerable<TKey> keys, out TValue v)

Parameters

src IDictionary<TKey, TValue>

The source dictionary.

keys IEnumerable<TKey>

The collection of keys to check.

v TValue

When this method returns, contains the value associated with the first matching key, if a key is found; otherwise, the default value for the type of the value parameter.

Returns

bool

true if any of the keys was found; otherwise, false.

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.