Class PropertyExt
Extension methods for accessing properties of a IDictionary<TKey, TValue> with K is string and T is object.
public static class PropertyExt
- Inheritance
-
PropertyExt
- Inherited Members
Methods
GetBool(IDictionary<string, object?>, string, bool)
Return a property's boolean value or defaultVal if not existing or not convertible to bool.
public static bool GetBool(this IDictionary<string, object?> prop, string propKey, bool defaultVal)
Parameters
propIDictionary<string, object>propKeystringdefaultValbool
Returns
GetInt(IDictionary<string, object?>, string, int)
Return a property's integer value or defaultVal if not existing or not convertible to int.
public static int GetInt(this IDictionary<string, object?> prop, string propKey, int defaultVal)
Parameters
propIDictionary<string, object>propKeystringdefaultValint
Returns
GetOrSet(IDictionary<string, object?>, string, object?)
Return a property's value or defaultVal if not existing - in that case is also set as new properties value.
public static object? GetOrSet(this IDictionary<string, object?> prop, string propKey, object? defaultVal)
Parameters
propIDictionary<string, object>propKeystringdefaultValobject
Returns
GetString(IDictionary<string, object?>, string)
Return a property's string value or null if not existing or not a string.
public static string? GetString(this IDictionary<string, object?> prop, string propKey)
Parameters
propIDictionary<string, object>propKeystring
Returns
GetString(IDictionary<string, object?>, string, string?)
Return a property's string value or defaultVal if not existing or not a string.
public static string? GetString(this IDictionary<string, object?> prop, string propKey, string? defaultVal)
Parameters
propIDictionary<string, object>propKeystringdefaultValstring
Returns
ResolvedProperty(IDictionary<string, object?>, string)
Resolved property value.
public static object ResolvedProperty(this IDictionary<string, object?> prop, string propSpecifier)
Parameters
propIDictionary<string, object>A properties dictionary
propSpecifierstringA property spcifier. If it is a name or property path enclosed in brackets like '[name.subKey]', the contents of the bracket are tried to be resolved with TryResolveValue(IDictionary<string, object?>, string, out object, out string?, char)
Returns
- object
The resolved property value given by the
propSpecifieror if could not be resolved as a property, thepropSpecifierit self.
SetResolvedValue(IDictionary<string, object?>, string, object?, out string?, char)
Set val to resolved (optionaly) nested properties dictionary.
public static bool SetResolvedValue(this IDictionary<string, object?> prop, string propKeyPath, object? val, out string? resolvedKey, char pathSep = '.')
Parameters
propIDictionary<string, object>(optionaly nested) properties dictionary
propKeyPathstringproperties key path (using '.' as path delimiter)
valobjectvalue to be set
resolvedKeystringresolved key (last token of the path on success)
pathSepcharOptional path seperator char (defaults to '.')
Returns
- bool
true if value could be set
Remarks
Assuming a propKeyPath of "p1.p2.p3". This would be (tried)
to be resolved like: properties["p1"]["p2"]["p3"] = val,
Every but the last tokens of the propKeyPath that could not be resolved into a dictionary value
gets created as a new dictionary, if not already existing. If it exists, but is not of dictionary type - false is returned.
ToReadonly(IDictionary<string, object?>)
Convert IReadOnlyDictionary<TKey, TValue> into read-only IDictionary<TKey, TValue>.
public static IReadOnlyDictionary<string, object?> ToReadonly(this IDictionary<string, object?> prop)
Parameters
propIDictionary<string, object>
Returns
TryResolveValue(IDictionary<string, object?>, string, out object, out string?, char)
Tries to resolve a value from (optionaly) nested properties dictionaries.
public static bool TryResolveValue(this IDictionary<string, object?> prop, string propKeyPath, out object val, out string? resolvedKey, char pathSep = '.')
Parameters
propIDictionary<string, object>(optionaly nested) properties dictionary
propKeyPathstringproperties key path (using
pathSepas path separator)valobjectresolved value
resolvedKeystringresolved key
pathSepcharOptional path seperator char (defaults to '.')
Returns
- bool
true if a value could be resolved using the
propKeyPath
Remarks
Assuming a propKeyPath of "p1.p2.p3". This would be (tried)
to be resolved like: properties["p1"]["p2"]["p3"],
The first key token of the propKeyPath that is associated with a non dictionary value (or the last)
is returned in resolvedKey