Extension methods for the BCL Dictionaries.
More...
|
static TValue | GetOrThrow< TKey, TValue > (this IReadOnlyDictionary< TKey, TValue > dictionary, TKey key, Func< Exception > errorCreator) |
| Get the value for given dictionary key. If no value can be found, it will throw an exception generated from the errorCreator function. More...
|
|
static TValue | GetValueOr< TKey, TValue > (this IReadOnlyDictionary< TKey, TValue > dictionary, TKey key, Func< TValue > valueProducer) |
| Same as the Regular GetOrDefault except this one takes a factory to produce the value. More...
|
|
static Dictionary< TKey, TNewValue > | SelectValues< TKey, TOldValue, TNewValue > (this IReadOnlyDictionary< TKey, TOldValue > dictionary, Func< TOldValue, TNewValue > selector) |
| Returns a new dictionary after applying the provided function to each value from the given dictionary. More...
|
|
static async Task< Dictionary< TKey, TVal > > | AwaitTasksInValuesAsync< TKey, TVal > (this IReadOnlyDictionary< TKey, Task< TVal >> dictionaryToAwait) |
| Given a dictionary of <TKey, Task<TVal>> it awaits all the Tasks in parallel, and constructs a new dictionary<TKey, TValgt;. More...
|
|
Extension methods for the BCL Dictionaries.
◆ AwaitTasksInValuesAsync< TKey, TVal >()
static async Task<Dictionary<TKey, TVal> > AwaitTasksInValuesAsync< TKey, TVal > |
( |
this IReadOnlyDictionary< TKey, Task< TVal >> |
dictionaryToAwait | ) |
|
|
inlinestatic |
Given a dictionary of <TKey, Task<TVal>> it awaits all the Tasks in parallel, and constructs a new dictionary<TKey, TValgt;.
- Parameters
-
dictionaryToAwait | The dictionary with tasks to await. |
///
- Template Parameters
-
TKey | Type of the dictionaries keys. |
TVal | Type of the dictionaries values. |
- Returns
- A new dictionary with all the Tasks in the values turned into their actual values.
◆ GetOrThrow< TKey, TValue >()
static TValue GetOrThrow< TKey, TValue > |
( |
this IReadOnlyDictionary< TKey, TValue > |
dictionary, |
|
|
TKey |
key, |
|
|
Func< Exception > |
errorCreator |
|
) |
| |
|
inlinestatic |
Get the value for given dictionary key. If no value can be found, it will throw an exception generated from the errorCreator function.
var myDictionary = new Dictionary<string, string> {
{"myKey", "myValue"}
}
myDictionary.GetOrThrow("myKey", () => new ArgumentException("tried to get invalid key"));
myDictionary.GetOrThrow("nonExistingKey", () => new ArgumentException("tried to get invalid key"));
◆ GetValueOr< TKey, TValue >()
static TValue GetValueOr< TKey, TValue > |
( |
this IReadOnlyDictionary< TKey, TValue > |
dictionary, |
|
|
TKey |
key, |
|
|
Func< TValue > |
valueProducer |
|
) |
| |
|
inlinestatic |
Same as the Regular GetOrDefault except this one takes a factory to produce the value.
◆ SelectValues< TKey, TOldValue, TNewValue >()
static Dictionary<TKey, TNewValue> SelectValues< TKey, TOldValue, TNewValue > |
( |
this IReadOnlyDictionary< TKey, TOldValue > |
dictionary, |
|
|
Func< TOldValue, TNewValue > |
selector |
|
) |
| |
|
inlinestatic |
Returns a new dictionary after applying the provided function to each value from the given dictionary.
- Template Parameters
-
TKey | Key Type. |
TOldValue | Original Type. |
TNewValue | New Type. |
- Parameters
-
dictionary | Source Dictionary. |
selector | Selector function. |
var myDictionary = new Dictionary<string, string> {
{"myKey", "2"}
}
myDictionary.SelectValues(oldValue => int.Parse(oldValue, CultureInfo.InvariantCulture));
var myDictionary = new Dictionary<string, string> {
{"myKey", "bar"}
}
myDictionary.SelectValues(oldValue => int.Parse(oldValue, CultureInfo.InvariantCulture));
- Returns
- Dictioanary<TKey, TNewValue>.
The documentation for this class was generated from the following file: