Table of Contents

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

dict IDictionary<string, object>

Source dictionary.

key string

Key to look up.

fallback string

Nullable 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

dict IDictionary<string, object>

Source dictionary.

key string

Key to look up.

fallback string

Fallback 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

dict IDictionary<TKey, TValue>

Source dictionary.

key TKey

Key to look up.

value TValue

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

TKey

Dictionary key type.

TValue

Dictionary value type (reference type).