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
output
IDictionary<TKey, TValue>The dictionary to add the key-value pair to. Cannot be null.
kvp
KeyValuePair<TKey, TValue>The key-value pair to add.
Type Parameters
TKey
TValue
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
source
IDictionary<TKey, TValue>keys
IEnumerable<TKey>
Returns
- IEnumerable<TValue>
Type Parameters
TValue
TKey
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
output
IDictionary<TKey, TValue>The dictionary to remove the key-value pair from. Cannot be null.
kvp
KeyValuePair<TKey, TValue>The key-value pair to remove.
Type Parameters
TKey
TValue
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
output
IEnumerable<KeyValuePair<TKey, TValue>>input
IEnumerable<KeyValuePair<TKey, TValue>>addAction
Action<TKey, TValue>updateAction
Action<TKey, TValue>removeAction
Func<TKey, bool>
Type Parameters
TKey
TValue
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
output
IEnumerable<KeyValuePair<TKey, TValueOutput>>input
IEnumerable<KeyValuePair<TKey, TValueInput>>areRepresentingTheSameValue
Func<TValueInput, TValueOutput, bool>fromValueInputTypeToValueOutputTypeConversion
Func<TValueInput, TValueOutput>addAction
Action<TKey, TValueOutput>updateAction
Action<TKey, TValueOutput>removeAction
Func<TKey, bool>
Type Parameters
TKey
TValueInput
TValueOutput
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
output
IEnumerable<KeyValuePair<TKeyOutput, TValue>>input
IEnumerable<KeyValuePair<TKeyInput, TValue>>areRepresentingTheSameKey
Func<TKeyInput, TKeyOutput, bool>fromKeyInputTypeToKeyOutputTypeConversion
Func<TKeyInput, TKeyOutput>addAction
Action<TKeyOutput, TValue>updateAction
Action<TKeyOutput, TValue>removeAction
Func<TKeyOutput, bool>
Type Parameters
TKeyInput
TKeyOutput
TValue
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
output
IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>The output collection to update.
input
IEnumerable<KeyValuePair<TKeyInput, TValueInput>>The input collection to use for updates.
areRepresentingTheSameKey
Func<TKeyInput, TKeyOutput, bool>Function to determine if two keys represent the same key.
fromKeyInputTypeToKeyOutputTypeConversion
Func<TKeyInput, TKeyOutput>Function to convert input keys to output keys.
areRepresentingTheSameValue
Func<TValueInput, TValueOutput, bool>Function to determine if two values represent the same value.
fromValueInputTypeToValueOutputTypeConversion
Func<TValueInput, TValueOutput>Function to convert input values to output values.
addAction
Action<TKeyOutput, TValueOutput>Action to perform when adding an item.
updateAction
Action<TKeyOutput, TValueOutput>Action to perform when updating an item.
removeAction
Func<TKeyOutput, bool>Function to perform when removing an item.
Type Parameters
TKeyInput
The type of the input dictionary keys.
TValueInput
The type of the input dictionary values.
TKeyOutput
The type of the output dictionary keys.
TValueOutput
The 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
output
IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>input
IEnumerable<KeyValuePair<TKeyInput, TValueInput>>areRepresentingTheSameKey
Func<TKeyInput, TKeyOutput, bool>fromKeyInputTypeToKeyOutputTypeConversion
Func<TKeyInput, TKeyOutput>fromValueInputTypeToValueOutputTypeConversion
Func<TValueInput, TValueOutput>addAction
Action<TKeyOutput, TValueOutput>updateAction
Action<TKeyOutput, TValueOutput>removeAction
Func<TKeyOutput, bool>
Type Parameters
TKeyInput
TValueInput
TKeyOutput
TValueOutput
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
output
IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>input
IEnumerable<KeyValuePair<TKeyInput, TValueInput>>fromKeyInputTypeToKeyOutputTypeConversion
Func<TKeyInput, TKeyOutput>areRepresentingTheSameValue
Func<TValueInput, TValueOutput, bool>fromValueInputTypeToValueOutputTypeConversion
Func<TValueInput, TValueOutput>addAction
Action<TKeyOutput, TValueOutput>updateAction
Action<TKeyOutput, TValueOutput>removeAction
Func<TKeyOutput, bool>
Type Parameters
TKeyInput
TValueInput
TKeyOutput
TValueOutput
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
output
IEnumerable<KeyValuePair<TKeyOutput, TValueOutput>>input
IEnumerable<KeyValuePair<TKeyInput, TValueInput>>fromKeyInputTypeToKeyOutputTypeConversion
Func<TKeyInput, TKeyOutput>fromValueInputTypeToValueOutputTypeConversion
Func<TValueInput, TValueOutput>addAction
Action<TKeyOutput, TValueOutput>updateAction
Action<TKeyOutput, TValueOutput>removeAction
Func<TKeyOutput, bool>
Type Parameters
TKeyInput
TValueInput
TKeyOutput
TValueOutput
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
output
IDictionary<TKey, TValue>The dictionary to update the key-value pair in. Cannot be null.
kvp
KeyValuePair<TKey, TValue>The key-value pair to update.
Type Parameters
TKey
TValue