Table of Contents

Class IDictionaryExtensions

Namespace
Songhay.Extensions
Assembly
SonghayCore.dll
public static class IDictionaryExtensions
Inheritance
IDictionaryExtensions
Inherited Members

Methods

ToNameValueCollection<TKey, TValue>(IDictionary<TKey, TValue>)

public static NameValueCollection ToNameValueCollection<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)

Parameters

dictionary IDictionary<TKey, TValue>

The set.

Returns

NameValueCollection

Type Parameters

TKey

The type of the key.

TValue

The type of the value.

Remarks

ToShallowClone<TKey, TValue>(IDictionary<TKey, TValue>?)

Converts the IDictionary<TKey, TValue> to a shallow clone.

public static IDictionary<TKey, TValue> ToShallowClone<TKey, TValue>(this IDictionary<TKey, TValue>? dictionary) where TKey : notnull

Parameters

dictionary IDictionary<TKey, TValue>

the IDictionary<TKey, TValue>

Returns

IDictionary<TKey, TValue>

Type Parameters

TKey

The type of the key.

TValue

The type of the value.

Remarks

For more detail see “Clone a Dictionary in C#” [https://www.techiedelight.com/clone-a-dictionary-in-csharp/]

TryGetValueWithKey<TKey, TValue>(IDictionary<TKey, TValue>?, TKey)

Tries to get value with the specified key.

public static TValue? TryGetValueWithKey<TKey, TValue>(this IDictionary<TKey, TValue>? dictionary, TKey key)

Parameters

dictionary IDictionary<TKey, TValue>

The dictionary.

key TKey

The key.

Returns

TValue

Type Parameters

TKey

The type of the key.

TValue

The type of the value.

TryGetValueWithKey<TKey, TValue>(IDictionary<TKey, TValue>?, TKey?, bool)

Tries to get value with the specified key.

public static TValue? TryGetValueWithKey<TKey, TValue>(this IDictionary<TKey, TValue>? dictionary, TKey? key, bool throwException)

Parameters

dictionary IDictionary<TKey, TValue>

The dictionary.

key TKey

The key.

throwException bool

When true, throw an exception when retrieval fails.

Returns

TValue

Type Parameters

TKey

The type of the key.

TValue

The type of the value.

WithPair<TKey, TValue>(IDictionary<TKey, TValue?>?, KeyValuePair<TKey, TValue?>?)

Returns the IDictionary<TKey, TValue> with the specified pair.

public static IDictionary<TKey, TValue?> WithPair<TKey, TValue>(this IDictionary<TKey, TValue?>? dictionary, KeyValuePair<TKey, TValue?>? pair) where TKey : notnull

Parameters

dictionary IDictionary<TKey, TValue>

the IDictionary<TKey, TValue>

pair KeyValuePair<TKey, TValue>?

the KeyValuePair<TKey, TValue>

Returns

IDictionary<TKey, TValue>

Type Parameters

TKey

The type of the key.

TValue

The type of the value.

WithPair<TKey, TValue>(IDictionary<TKey, TValue?>?, TKey?, TValue?)

Returns the IDictionary<TKey, TValue> with the specified pair.

public static IDictionary<TKey, TValue?> WithPair<TKey, TValue>(this IDictionary<TKey, TValue?>? dictionary, TKey? key, TValue? value) where TKey : notnull

Parameters

dictionary IDictionary<TKey, TValue>

the IDictionary<TKey, TValue>

key TKey

the key

value TValue

the value

Returns

IDictionary<TKey, TValue>

Type Parameters

TKey

The type of the key.

TValue

The type of the value.

WithPairs<TKey, TValue>(IDictionary<TKey, TValue?>?, IEnumerable<KeyValuePair<TKey, TValue?>>?)

Returns the IDictionary<TKey, TValue> with the specified pairs.

public static IDictionary<TKey, TValue?> WithPairs<TKey, TValue>(this IDictionary<TKey, TValue?>? dictionary, IEnumerable<KeyValuePair<TKey, TValue?>>? pairs) where TKey : notnull

Parameters

dictionary IDictionary<TKey, TValue>

the IDictionary<TKey, TValue>

pairs IEnumerable<KeyValuePair<TKey, TValue>>

The pairs to add.

Returns

IDictionary<TKey, TValue>

Type Parameters

TKey

The type of the key.

TValue

The type of the value.