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
dictionary
IDictionary<TKey, TValue>keyValues
IEnumerable<KeyValuePair<TKey, TValue>>KeyValuePair<TKey, TValue>s to add.
Type Parameters
TKey
Type of key.
TValue
Type 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
dictionary
IDictionary<TKey, TValue>
Returns
- IDictionary<TKey, TValue>
Read-only dictionary.
Type Parameters
TKey
Type of key.
TValue
Type 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
dictionary
IDictionary<TKey, TValue>key
TKeyKey.
defaultValue
TValue?Default value.
Returns
- TValue?
Value of given default value.
Type Parameters
TKey
Type of key in dictionary.
TValue
Type 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
dictionary
IDictionary<TKey, TValue>key
TKeyKey.
defaultValue
TValueDefault value.
Returns
- TValue
Value of given default value.
Type Parameters
TKey
Type of key in dictionary.
TValue
Type 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
dictionary
Dictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is empty.
Type Parameters
TKey
Type of key in dictionary.
TValue
Type 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
dictionary
IDictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is empty.
Type Parameters
TKey
Type of key in dictionary.
TValue
Type 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
dictionary
Dictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is not empty.
Type Parameters
TKey
Type of key in dictionary.
TValue
Type 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
dictionary
IDictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is not empty.
Type Parameters
TKey
Type of key in dictionary.
TValue
Type 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
dictionary
Dictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is null or empty.
Type Parameters
TKey
Type of key in dictionary.
TValue
Type 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
dictionary
IDictionary<TKey, TValue>Dictionary to check.
Returns
- bool
True if the dictionary is null or empty.
Type Parameters
TKey
Type of key in dictionary.
TValue
Type 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
dictionary
IDictionary<TKey, TValue>key
TKeyKey.
value
TOutGot value.
Returns
- bool
True if value has been got as given type successfully.
Type Parameters
TKey
Type of key in dictionary.
TValue
Type of value in dictionary.
TOut
Desired type of value.