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
dictionaryIDictionary<TKey, TValue>The set.
Returns
Type Parameters
TKeyThe type of the key.
TValueThe 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
dictionaryIDictionary<TKey, TValue>
Returns
- IDictionary<TKey, TValue>
Type Parameters
TKeyThe type of the key.
TValueThe type of the value.
Remarks
For more detail see “Clone a Dictionary in C#” [https://www.techiedelight.com/clone-a-dictionary-in-csharp/]
ToUriQueryString<TKey, TValue>(IDictionary<TKey, TValue?>?)
Converts the specified dictionary into a Query string.
public static string ToUriQueryString<TKey, TValue>(this IDictionary<TKey, TValue?>? dictionary)
Parameters
dictionaryIDictionary<TKey, TValue>
Returns
Type Parameters
TKeyThe type of the key.
TValueThe type of the value.
Remarks
No URI encoding logic is used by this method.
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
dictionaryIDictionary<TKey, TValue>The dictionary.
keyTKeyThe key.
Returns
- TValue
Type Parameters
TKeyThe type of the key.
TValueThe 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
dictionaryIDictionary<TKey, TValue>The dictionary.
keyTKeyThe key.
throwExceptionboolWhen
true, throw an exception when retrieval fails.
Returns
- TValue
Type Parameters
TKeyThe type of the key.
TValueThe type of the value.
UnionAsDictionary<TKey, TValue>(IDictionary<TKey, TValue?>?, IDictionary<TKey, TValue?>?)
Invokes the Union<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) method with the specified dictionaries and calls ToDictionary<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>) on the result.
public static IDictionary<TKey, TValue?>? UnionAsDictionary<TKey, TValue>(this IDictionary<TKey, TValue?>? dictionary1, IDictionary<TKey, TValue?>? dictionary2) where TKey : notnull
Parameters
dictionary1IDictionary<TKey, TValue>dictionary2IDictionary<TKey, TValue>
Returns
- IDictionary<TKey, TValue>
Type Parameters
TKeyThe type of the key.
TValueThe type of the value.
Remarks
When Union<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) is called .NET returns a collection of KeyValuePair<TKey, TValue> to avoid losing dictionary entries with the same key. This member disregards this danger and ensures a dictionary is returned.
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
dictionaryIDictionary<TKey, TValue>pairKeyValuePair<TKey, TValue>?
Returns
- IDictionary<TKey, TValue>
Type Parameters
TKeyThe type of the key.
TValueThe 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
dictionaryIDictionary<TKey, TValue>keyTKeythe key
valueTValuethe value
Returns
- IDictionary<TKey, TValue>
Type Parameters
TKeyThe type of the key.
TValueThe type of the value.
WithPair<TKey, TValue>(IDictionary<TKey, TValue?>?, TKey?, TValue?, Func<bool>?)
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, Func<bool>? condition) where TKey : notnull
Parameters
dictionaryIDictionary<TKey, TValue>keyTKeythe key
valueTValuethe value
conditionFunc<bool>The condition.
Returns
- IDictionary<TKey, TValue>
Type Parameters
TKeyThe type of the key.
TValueThe 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
dictionaryIDictionary<TKey, TValue>pairsIEnumerable<KeyValuePair<TKey, TValue>>The pairs to add.
Returns
- IDictionary<TKey, TValue>
Type Parameters
TKeyThe type of the key.
TValueThe type of the value.