Class DictionaryExtensions
- Namespace
- Plugin.BaseTypeExtensions
- Assembly
- Plugin.BaseTypeExtensions.dll
Provides extension methods for working with IDictionary<TKey, TValue> and related dictionary types.
public static class DictionaryExtensions
- Inheritance
-
DictionaryExtensions
- Inherited Members
Methods
Add<TKey, TValue>(IDictionary<TKey, TValue>, KeyValuePair<TKey, TValue>)
Adds a key-value pair to the dictionary.
public static void Add<TKey, TValue>(this IDictionary<TKey, TValue> output, KeyValuePair<TKey, TValue> kvp)
Parameters
outputIDictionary<TKey, TValue>The dictionary to add the key-value pair to. Cannot be null.
kvpKeyValuePair<TKey, TValue>The key-value pair to add.
Type Parameters
TKeyTValue
GetValuesForKeys<TValue, TKey>(IDictionary<TKey, TValue>, IEnumerable<TKey>)
Gets the values for the specified keys from the dictionary.
public static IEnumerable<TValue> GetValuesForKeys<TValue, TKey>(this IDictionary<TKey, TValue> source, IEnumerable<TKey> keys)
Parameters
sourceIDictionary<TKey, TValue>keysIEnumerable<TKey>
Returns
- IEnumerable<TValue>
Type Parameters
TValueTKey
Remove<TKey, TValue>(IDictionary<TKey, TValue>, KeyValuePair<TKey, TValue>)
Removes a key-value pair from the dictionary.
public static void Remove<TKey, TValue>(this IDictionary<TKey, TValue> output, KeyValuePair<TKey, TValue> kvp)
Parameters
outputIDictionary<TKey, TValue>The dictionary to remove the key-value pair from. Cannot be null.
kvpKeyValuePair<TKey, TValue>The key-value pair to remove.
Type Parameters
TKeyTValue
UpdateFromAsync<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>?, IEnumerable<KeyValuePair<TKey, TValue>>?, Func<TKey, TValue, CancellationToken, Task>?, Func<TKey, CancellationToken, Task<bool>>?, CancellationToken)
Asynchronously updates the output collection by adding and removing specified items.
public static Task UpdateFromAsync<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> output, IEnumerable<KeyValuePair<TKey, TValue>>? addedItems = null, IEnumerable<KeyValuePair<TKey, TValue>>? removedItems = null, Func<TKey, TValue, CancellationToken, Task>? addAction = null, Func<TKey, CancellationToken, Task<bool>>? removeAction = null, CancellationToken cancellationToken = default) where TKey : notnull
Parameters
outputIEnumerable<KeyValuePair<TKey, TValue>>The collection to update.
addedItemsIEnumerable<KeyValuePair<TKey, TValue>>The items to add to the collection.
removedItemsIEnumerable<KeyValuePair<TKey, TValue>>The items to remove from the collection.
addActionFunc<TKey, TValue, CancellationToken, Task>Async action to perform when adding an item. If null and output is an IDictionary, uses the dictionary's Add method.
removeActionFunc<TKey, CancellationToken, Task<bool>>Async function to perform when removing an item. If null and output is an IDictionary, uses the dictionary's Remove method.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
Type Parameters
TKeyThe type of the dictionary keys.
TValueThe type of the dictionary values.
UpdateFromAsync<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>, IEnumerable<KeyValuePair<TKeyInput, TValueInput>>, Func<TKeyInput, TKeyOutput, bool>, Func<TKeyInput, TKeyOutput>, Func<TValueInput, TValueOutput, bool>, Func<TValueInput, TValueOutput>, Func<TKeyOutput, TValueOutput, CancellationToken, Task>?, Func<TKeyOutput, TValueOutput, CancellationToken, Task>?, Func<TKeyOutput, CancellationToken, Task<bool>>?, CancellationToken)
Asynchronously updates the output collection from the input collection with custom key and value comparison, conversion, and optional actions for adding, updating, and removing items.
public static Task UpdateFromAsync<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(this IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>> output, IEnumerable<KeyValuePair<TKeyInput, TValueInput>> input, Func<TKeyInput, TKeyOutput, bool> areRepresentingTheSameKey, Func<TKeyInput, TKeyOutput> fromKeyInputTypeToKeyOutputTypeConversion, Func<TValueInput, TValueOutput, bool> areRepresentingTheSameValue, Func<TValueInput, TValueOutput> fromValueInputTypeToValueOutputTypeConversion, Func<TKeyOutput, TValueOutput, CancellationToken, Task>? addAction = null, Func<TKeyOutput, TValueOutput, CancellationToken, Task>? updateAction = null, Func<TKeyOutput, CancellationToken, Task<bool>>? removeAction = null, CancellationToken cancellationToken = default) where TKeyInput : notnull where TKeyOutput : notnull
Parameters
outputIEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>The output collection to update.
inputIEnumerable<KeyValuePair<TKeyInput, TValueInput>>The input collection to use for updates.
areRepresentingTheSameKeyFunc<TKeyInput, TKeyOutput, bool>Function to determine if two keys represent the same key.
fromKeyInputTypeToKeyOutputTypeConversionFunc<TKeyInput, TKeyOutput>Function to convert input keys to output keys.
areRepresentingTheSameValueFunc<TValueInput, TValueOutput, bool>Function to determine if two values represent the same value.
fromValueInputTypeToValueOutputTypeConversionFunc<TValueInput, TValueOutput>Function to convert input values to output values.
addActionFunc<TKeyOutput, TValueOutput, CancellationToken, Task>Async action to perform when adding an item.
updateActionFunc<TKeyOutput, TValueOutput, CancellationToken, Task>Async action to perform when updating an item.
removeActionFunc<TKeyOutput, CancellationToken, Task<bool>>Async function to perform when removing an item.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
Type Parameters
TKeyInputThe type of the input dictionary keys.
TValueInputThe type of the input dictionary values.
TKeyOutputThe type of the output dictionary keys.
TValueOutputThe type of the output dictionary values.
UpdateFrom<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, Action<TKey, TValue>?, Action<TKey, TValue>?, Func<TKey, bool>?)
Updates the output collection from the input collection with optional actions for adding, updating, and removing items.
public static void UpdateFrom<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> output, IEnumerable<KeyValuePair<TKey, TValue>> input, Action<TKey, TValue>? addAction = null, Action<TKey, TValue>? updateAction = null, Func<TKey, bool>? removeAction = null) where TKey : notnull
Parameters
outputIEnumerable<KeyValuePair<TKey, TValue>>inputIEnumerable<KeyValuePair<TKey, TValue>>addActionAction<TKey, TValue>updateActionAction<TKey, TValue>removeActionFunc<TKey, bool>
Type Parameters
TKeyTValue
UpdateFrom<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>?, IEnumerable<KeyValuePair<TKey, TValue>>?, Action<TKey, TValue>?, Func<TKey, bool>?)
Updates the output collection by adding and removing specified items.
public static void UpdateFrom<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> output, IEnumerable<KeyValuePair<TKey, TValue>>? addedItems = null, IEnumerable<KeyValuePair<TKey, TValue>>? removedItems = null, Action<TKey, TValue>? addAction = null, Func<TKey, bool>? removeAction = null) where TKey : notnull
Parameters
outputIEnumerable<KeyValuePair<TKey, TValue>>The collection to update.
addedItemsIEnumerable<KeyValuePair<TKey, TValue>>The items to add to the collection.
removedItemsIEnumerable<KeyValuePair<TKey, TValue>>The items to remove from the collection.
addActionAction<TKey, TValue>Action to perform when adding an item. If null and output is an IDictionary, uses the dictionary's Add method.
removeActionFunc<TKey, bool>Function to perform when removing an item. If null and output is an IDictionary, uses the dictionary's Remove method.
Type Parameters
TKeyThe type of the dictionary keys.
TValueThe type of the dictionary values.
UpdateFrom<TKey, TValueInput, TValueOutput>(IEnumerable<KeyValuePair<TKey, TValueOutput>>, IEnumerable<KeyValuePair<TKey, TValueInput>>, Func<TValueInput, TValueOutput, bool>, Func<TValueInput, TValueOutput>, Action<TKey, TValueOutput>?, Action<TKey, TValueOutput>?, Func<TKey, bool>?)
Updates the output collection from the input collection with key conversion and optional actions for adding, updating, and removing items.
public static void UpdateFrom<TKey, TValueInput, TValueOutput>(this IEnumerable<KeyValuePair<TKey, TValueOutput>> output, IEnumerable<KeyValuePair<TKey, TValueInput>> input, Func<TValueInput, TValueOutput, bool> areRepresentingTheSameValue, Func<TValueInput, TValueOutput> fromValueInputTypeToValueOutputTypeConversion, Action<TKey, TValueOutput>? addAction = null, Action<TKey, TValueOutput>? updateAction = null, Func<TKey, bool>? removeAction = null) where TKey : notnull
Parameters
outputIEnumerable<KeyValuePair<TKey, TValueOutput>>inputIEnumerable<KeyValuePair<TKey, TValueInput>>areRepresentingTheSameValueFunc<TValueInput, TValueOutput, bool>fromValueInputTypeToValueOutputTypeConversionFunc<TValueInput, TValueOutput>addActionAction<TKey, TValueOutput>updateActionAction<TKey, TValueOutput>removeActionFunc<TKey, bool>
Type Parameters
TKeyTValueInputTValueOutput
UpdateFrom<TKeyInput, TKeyOutput, TValue>(IEnumerable<KeyValuePair<TKeyOutput, TValue>>, IEnumerable<KeyValuePair<TKeyInput, TValue>>, Func<TKeyInput, TKeyOutput, bool>, Func<TKeyInput, TKeyOutput>, Action<TKeyOutput, TValue>?, Action<TKeyOutput, TValue>?, Func<TKeyOutput, bool>?)
Updates the output collection from the input collection with key and value conversion and optional actions for adding, updating, and removing items.
public static void UpdateFrom<TKeyInput, TKeyOutput, TValue>(this IEnumerable<KeyValuePair<TKeyOutput, TValue>> output, IEnumerable<KeyValuePair<TKeyInput, TValue>> input, Func<TKeyInput, TKeyOutput, bool> areRepresentingTheSameKey, Func<TKeyInput, TKeyOutput> fromKeyInputTypeToKeyOutputTypeConversion, Action<TKeyOutput, TValue>? addAction = null, Action<TKeyOutput, TValue>? updateAction = null, Func<TKeyOutput, bool>? removeAction = null) where TKeyInput : notnull where TKeyOutput : notnull
Parameters
outputIEnumerable<KeyValuePair<TKeyOutput, TValue>>inputIEnumerable<KeyValuePair<TKeyInput, TValue>>areRepresentingTheSameKeyFunc<TKeyInput, TKeyOutput, bool>fromKeyInputTypeToKeyOutputTypeConversionFunc<TKeyInput, TKeyOutput>addActionAction<TKeyOutput, TValue>updateActionAction<TKeyOutput, TValue>removeActionFunc<TKeyOutput, bool>
Type Parameters
TKeyInputTKeyOutputTValue
UpdateFrom<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>, IEnumerable<KeyValuePair<TKeyInput, TValueInput>>, Func<TKeyInput, TKeyOutput, bool>, Func<TKeyInput, TKeyOutput>, Func<TValueInput, TValueOutput, bool>, Func<TValueInput, TValueOutput>, Action<TKeyOutput, TValueOutput>?, Action<TKeyOutput, TValueOutput>?, Func<TKeyOutput, bool>?)
Updates the output collection from the input collection with custom key and value comparison, conversion, and optional actions for adding, updating, and removing items.
public static void UpdateFrom<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(this IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>> output, IEnumerable<KeyValuePair<TKeyInput, TValueInput>> input, Func<TKeyInput, TKeyOutput, bool> areRepresentingTheSameKey, Func<TKeyInput, TKeyOutput> fromKeyInputTypeToKeyOutputTypeConversion, Func<TValueInput, TValueOutput, bool> areRepresentingTheSameValue, Func<TValueInput, TValueOutput> fromValueInputTypeToValueOutputTypeConversion, Action<TKeyOutput, TValueOutput>? addAction = null, Action<TKeyOutput, TValueOutput>? updateAction = null, Func<TKeyOutput, bool>? removeAction = null) where TKeyInput : notnull where TKeyOutput : notnull
Parameters
outputIEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>The output collection to update.
inputIEnumerable<KeyValuePair<TKeyInput, TValueInput>>The input collection to use for updates.
areRepresentingTheSameKeyFunc<TKeyInput, TKeyOutput, bool>Function to determine if two keys represent the same key.
fromKeyInputTypeToKeyOutputTypeConversionFunc<TKeyInput, TKeyOutput>Function to convert input keys to output keys.
areRepresentingTheSameValueFunc<TValueInput, TValueOutput, bool>Function to determine if two values represent the same value.
fromValueInputTypeToValueOutputTypeConversionFunc<TValueInput, TValueOutput>Function to convert input values to output values.
addActionAction<TKeyOutput, TValueOutput>Action to perform when adding an item.
updateActionAction<TKeyOutput, TValueOutput>Action to perform when updating an item.
removeActionFunc<TKeyOutput, bool>Function to perform when removing an item.
Type Parameters
TKeyInputThe type of the input dictionary keys.
TValueInputThe type of the input dictionary values.
TKeyOutputThe type of the output dictionary keys.
TValueOutputThe type of the output dictionary values.
UpdateFrom<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>, IEnumerable<KeyValuePair<TKeyInput, TValueInput>>, Func<TKeyInput, TKeyOutput, bool>, Func<TKeyInput, TKeyOutput>, Func<TValueInput, TValueOutput>, Action<TKeyOutput, TValueOutput>?, Action<TKeyOutput, TValueOutput>?, Func<TKeyOutput, bool>?)
Updates the output collection from the input collection with key and value comparison and optional actions for adding, updating, and removing items.
public static void UpdateFrom<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(this IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>> output, IEnumerable<KeyValuePair<TKeyInput, TValueInput>> input, Func<TKeyInput, TKeyOutput, bool> areRepresentingTheSameKey, Func<TKeyInput, TKeyOutput> fromKeyInputTypeToKeyOutputTypeConversion, Func<TValueInput, TValueOutput> fromValueInputTypeToValueOutputTypeConversion, Action<TKeyOutput, TValueOutput>? addAction = null, Action<TKeyOutput, TValueOutput>? updateAction = null, Func<TKeyOutput, bool>? removeAction = null) where TKeyInput : notnull where TValueInput : IEquatable<TValueOutput> where TKeyOutput : notnull
Parameters
outputIEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>inputIEnumerable<KeyValuePair<TKeyInput, TValueInput>>areRepresentingTheSameKeyFunc<TKeyInput, TKeyOutput, bool>fromKeyInputTypeToKeyOutputTypeConversionFunc<TKeyInput, TKeyOutput>fromValueInputTypeToValueOutputTypeConversionFunc<TValueInput, TValueOutput>addActionAction<TKeyOutput, TValueOutput>updateActionAction<TKeyOutput, TValueOutput>removeActionFunc<TKeyOutput, bool>
Type Parameters
TKeyInputTValueInputTKeyOutputTValueOutput
UpdateFrom<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>, IEnumerable<KeyValuePair<TKeyInput, TValueInput>>, Func<TKeyInput, TKeyOutput>, Func<TValueInput, TValueOutput, bool>, Func<TValueInput, TValueOutput>, Action<TKeyOutput, TValueOutput>?, Action<TKeyOutput, TValueOutput>?, Func<TKeyOutput, bool>?)
Updates the output collection from the input collection with key and value comparison and optional actions for adding, updating, and removing items.
public static void UpdateFrom<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(this IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>> output, IEnumerable<KeyValuePair<TKeyInput, TValueInput>> input, Func<TKeyInput, TKeyOutput> fromKeyInputTypeToKeyOutputTypeConversion, Func<TValueInput, TValueOutput, bool> areRepresentingTheSameValue, Func<TValueInput, TValueOutput> fromValueInputTypeToValueOutputTypeConversion, Action<TKeyOutput, TValueOutput>? addAction = null, Action<TKeyOutput, TValueOutput>? updateAction = null, Func<TKeyOutput, bool>? removeAction = null) where TKeyInput : IEquatable<TKeyOutput> where TKeyOutput : notnull
Parameters
outputIEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>inputIEnumerable<KeyValuePair<TKeyInput, TValueInput>>fromKeyInputTypeToKeyOutputTypeConversionFunc<TKeyInput, TKeyOutput>areRepresentingTheSameValueFunc<TValueInput, TValueOutput, bool>fromValueInputTypeToValueOutputTypeConversionFunc<TValueInput, TValueOutput>addActionAction<TKeyOutput, TValueOutput>updateActionAction<TKeyOutput, TValueOutput>removeActionFunc<TKeyOutput, bool>
Type Parameters
TKeyInputTValueInputTKeyOutputTValueOutput
UpdateFrom<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>, IEnumerable<KeyValuePair<TKeyInput, TValueInput>>, Func<TKeyInput, TKeyOutput>, Func<TValueInput, TValueOutput>, Action<TKeyOutput, TValueOutput>?, Action<TKeyOutput, TValueOutput>?, Func<TKeyOutput, bool>?)
Updates the output collection from the input collection with key and value comparison and optional actions for adding, updating, and removing items.
public static void UpdateFrom<TKeyInput, TValueInput, TKeyOutput, TValueOutput>(this IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>> output, IEnumerable<KeyValuePair<TKeyInput, TValueInput>> input, Func<TKeyInput, TKeyOutput> fromKeyInputTypeToKeyOutputTypeConversion, Func<TValueInput, TValueOutput> fromValueInputTypeToValueOutputTypeConversion, Action<TKeyOutput, TValueOutput>? addAction = null, Action<TKeyOutput, TValueOutput>? updateAction = null, Func<TKeyOutput, bool>? removeAction = null) where TKeyInput : IEquatable<TKeyOutput> where TValueInput : IEquatable<TValueOutput> where TKeyOutput : notnull
Parameters
outputIEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>inputIEnumerable<KeyValuePair<TKeyInput, TValueInput>>fromKeyInputTypeToKeyOutputTypeConversionFunc<TKeyInput, TKeyOutput>fromValueInputTypeToValueOutputTypeConversionFunc<TValueInput, TValueOutput>addActionAction<TKeyOutput, TValueOutput>updateActionAction<TKeyOutput, TValueOutput>removeActionFunc<TKeyOutput, bool>
Type Parameters
TKeyInputTValueInputTKeyOutputTValueOutput
Update<TKey, TValue>(IDictionary<TKey, TValue>, KeyValuePair<TKey, TValue>)
Updates the value of a key-value pair in the dictionary.
public static void Update<TKey, TValue>(this IDictionary<TKey, TValue> output, KeyValuePair<TKey, TValue> kvp)
Parameters
outputIDictionary<TKey, TValue>The dictionary to update the key-value pair in. Cannot be null.
kvpKeyValuePair<TKey, TValue>The key-value pair to update.
Type Parameters
TKeyTValue