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
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, 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