Class DictionaryExtensions
- Namespace
- CarinaStudio.Collections
- Assembly
- CarinaStudio.AppBase.Core.dll
Extensions for IDictionary<TKey, TValue>.
public static class DictionaryExtensions
- Inheritance
-
DictionaryExtensions
- Inherited Members
Methods
AddAll<TKey, TValue>(IDictionary<TKey, TValue>, IEnumerable<KeyValuePair<TKey, TValue>>)
Add all KeyValuePair<TKey, TValue>s to dictionary.
public static void AddAll<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, IEnumerable<KeyValuePair<TKey, TValue>> keyValues) where TKey : notnull
Parameters
dictionaryIDictionary<TKey, TValue>keyValuesIEnumerable<KeyValuePair<TKey, TValue>>KeyValuePair<TKey, TValue>s to add.
Type Parameters
TKeyType of key.
TValueType of value.
AsReadOnly<TKey, TValue>(IDictionary<TKey, TValue>)
Make dictionary as read-only.
[Pure]
public static IDictionary<TKey, TValue> AsReadOnly<TKey, TValue>(this IDictionary<TKey, TValue> dictionary) where TKey : notnull
Parameters
dictionaryIDictionary<TKey, TValue>
Returns
- IDictionary<TKey, TValue>
Read-only dictionary.
Type Parameters
TKeyType of key.
TValueType of value.
GetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue?)
Get value with given key. The default value will be returned if value cannot be found.
public static TValue? GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue? defaultValue = null) where TKey : notnull where TValue : struct
Parameters
dictionaryIDictionary<TKey, TValue>keyTKeyKey.
defaultValueTValue?Default value.
Returns
- TValue?
Value of given default value.
Type Parameters
TKeyType of key in dictionary.
TValueType of value in dictionary.
GetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue?)
Get value with given key. The default value will be returned if value cannot be found.
public static TValue? GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue? defaultValue = null) where TKey : notnull where TValue : class
Parameters
dictionaryIDictionary<TKey, TValue>keyTKeyKey.
defaultValueTValueDefault value.
Returns
- TValue
Value of given default value.
Type Parameters
TKeyType of key in dictionary.
TValueType of value in dictionary.
IsEmpty<TKey, TValue>(Dictionary<TKey, TValue>)
Check whether the given dictionary is empty or not.
public static bool IsEmpty<TKey, TValue>(this Dictionary<TKey, TValue> dictionary) where TKey : notnull
Parameters
dictionaryDictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is empty.
Type Parameters
TKeyType of key in dictionary.
TValueType of value in dictionary.
Remarks
The method is available for target framework before .NET 9.
IsEmpty<TKey, TValue>(IDictionary<TKey, TValue>)
Check whether the given dictionary is empty or not.
public static bool IsEmpty<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
Parameters
dictionaryIDictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is empty.
Type Parameters
TKeyType of key in dictionary.
TValueType of value in dictionary.
Remarks
The method is available for target framework before .NET 9.
IsNotEmpty<TKey, TValue>(Dictionary<TKey, TValue>?)
Check whether the given dictionary is not empty or not.
public static bool IsNotEmpty<TKey, TValue>(this Dictionary<TKey, TValue>? dictionary) where TKey : notnull
Parameters
dictionaryDictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is not empty.
Type Parameters
TKeyType of key in dictionary.
TValueType of value in dictionary.
Remarks
The method is available for target framework before .NET 9.
IsNotEmpty<TKey, TValue>(IDictionary<TKey, TValue>?)
Check whether the given dictionary is not empty or not.
public static bool IsNotEmpty<TKey, TValue>(this IDictionary<TKey, TValue>? dictionary)
Parameters
dictionaryIDictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is not empty.
Type Parameters
TKeyType of key in dictionary.
TValueType of value in dictionary.
Remarks
The method is available for target framework before .NET 9.
IsNullOrEmpty<TKey, TValue>(Dictionary<TKey, TValue>?)
Check whether given dictionary is null/empty or not.
public static bool IsNullOrEmpty<TKey, TValue>(this Dictionary<TKey, TValue>? dictionary) where TKey : notnull
Parameters
dictionaryDictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is null or empty.
Type Parameters
TKeyType of key in dictionary.
TValueType of value in dictionary.
Remarks
The method is available for target framework before .NET 9.
IsNullOrEmpty<TKey, TValue>(IDictionary<TKey, TValue>?)
Check whether given dictionary is null/empty or not.
public static bool IsNullOrEmpty<TKey, TValue>(this IDictionary<TKey, TValue>? dictionary)
Parameters
dictionaryIDictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is null or empty.
Type Parameters
TKeyType of key in dictionary.
TValueType of value in dictionary.
Remarks
The method is available for target framework before .NET 9.
TryGetValue<TKey, TValue, TOut>(IDictionary<TKey, TValue>, TKey, out TOut)
Try getting value from dictionary as given type.
public static bool TryGetValue<TKey, TValue, TOut>(this IDictionary<TKey, TValue> dictionary, TKey key, out TOut value) where TKey : notnull where TOut : TValue
Parameters
dictionaryIDictionary<TKey, TValue>keyTKeyKey.
valueTOutGot value.
Returns
- bool
True if value has been got as given type successfully.
Type Parameters
TKeyType of key in dictionary.
TValueType of value in dictionary.
TOutDesired type of value.