Class IDictionaryExtensions
- Namespace
- Songhay.Extensions
- Assembly
- SonghayCore.dll
Extensions of IDictionary<TKey, TValue>.
public static class IDictionaryExtensions
- Inheritance
-
IDictionaryExtensions
- Inherited Members
Methods
ToNameValueCollection<TKey, TValue>(IDictionary<TKey, TValue>)
Converts the IDictionary<TKey, TValue> to the NameValueCollection.
public static NameValueCollection ToNameValueCollection<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
Parameters
dictionary
IDictionary<TKey, TValue>The set.
Returns
Type Parameters
TKey
The type of the key.
TValue
The type of the value.
Remarks
For detail, see https://stackoverflow.com/a/7230446/22944
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>
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
TKeyThe 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
TKeyThe key.
throwException
boolWhen
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>pair
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>key
TKeythe key
value
TValuethe 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>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.