Class DictionaryExtensions
- Namespace
- OverKizApi
- Assembly
- OverKizApi.dll
Nullable flow-friendly helpers for dictionaries.
public static class DictionaryExtensions
- Inheritance
-
DictionaryExtensions
- Inherited Members
Methods
GetNullableStringOr(IDictionary<string, object>, string, string?)
Gets a nullable string value for a key or a nullable fallback when not present.
public static string? GetNullableStringOr(this IDictionary<string, object> dict, string key, string? fallback = null)
Parameters
dictIDictionary<string, object>Source dictionary.
keystringKey to look up.
fallbackstringNullable fallback when key is missing.
Returns
- string
String value or nullable fallback.
GetStringOr(IDictionary<string, object>, string, string)
Gets a string value for a key or a fallback when not present. Assumes JSON deserialization never stores null values in the dictionary.
public static string GetStringOr(this IDictionary<string, object> dict, string key, string fallback = "Unknown")
Parameters
dictIDictionary<string, object>Source dictionary.
keystringKey to look up.
fallbackstringFallback string when key is missing.
Returns
- string
String value or fallback.
TryGetNonNull<TKey, TValue>(IDictionary<TKey, TValue>, TKey, out TValue?)
TryGetValue that also guarantees the value is non-null when the method returns true.
public static bool TryGetNonNull<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, out TValue? value) where TValue : class
Parameters
dictIDictionary<TKey, TValue>Source dictionary.
keyTKeyKey to look up.
valueTValueNon-null value when the method returns true.
Returns
- bool
True when the key exists and the associated value is not null; otherwise false.
Type Parameters
TKeyDictionary key type.
TValueDictionary value type (reference type).