Class ConfigProperties
Dictionary of configuration properties.
public class ConfigProperties : AbstractErrorHandledNamedValues<object?>, IDictionary<string, object?>, ICollection<KeyValuePair<string, object?>>, IReadOnlyDictionary<string, object?>, IReadOnlyCollection<KeyValuePair<string, object?>>, IEnumerable<KeyValuePair<string, object?>>, IEnumerable
- Inheritance
-
ConfigProperties
- Implements
- Inherited Members
- Extension Methods
Remarks
Uses a OrdinalIgnoreCase for the property names.
Constructors
ConfigProperties()
Default ctor
public ConfigProperties()
ConfigProperties(IEnumerable<KeyValuePair<string, object?>>)
Ctor to intialize from another properties dictionary.
public ConfigProperties(IEnumerable<KeyValuePair<string, object?>> other)
Parameters
other
IEnumerable<KeyValuePair<string, object>>
ConfigProperties(IEnumerable<KeyValuePair<string, object?>>, IEnumerable<KeyValuePair<string, object?>>)
Ctor to intialize from another properties dictionary and overriding properties.
public ConfigProperties(IEnumerable<KeyValuePair<string, object?>> other, IEnumerable<KeyValuePair<string, object?>> overridingProps)
Parameters
other
IEnumerable<KeyValuePair<string, object>>overridingProps
IEnumerable<KeyValuePair<string, object>>
ConfigProperties(int)
Ctor from capacity
public ConfigProperties(int capacity)
Parameters
capacity
int
Fields
EMPTY
Empty (read-only) config properties.
public static readonly IReadOnlyDictionary<string, object?> EMPTY
Field Value
Methods
GetBool(IReadOnlyDictionary<string, object?>, string, bool)
Return a property's boolean value or defaultVal
if not existing or not convertible to bool.
public static bool GetBool(IReadOnlyDictionary<string, object?> properties, string propKey, bool defaultVal)
Parameters
properties
IReadOnlyDictionary<string, object>propKey
stringdefaultVal
bool
Returns
GetInt(IReadOnlyDictionary<string, object?>, string, int)
Return a property's integer value or defaultVal
if not existing or not convertible to int.
public static int GetInt(IReadOnlyDictionary<string, object?> properties, string propKey, int defaultVal)
Parameters
properties
IReadOnlyDictionary<string, object>propKey
stringdefaultVal
int
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(IDictionary<string, object?> properties, string propKey, object defaultVal)
Parameters
properties
IDictionary<string, object>propKey
stringdefaultVal
object
Returns
GetString(IReadOnlyDictionary<string, object?>, string)
Return a property's string value or null if not existing or not a string.
public static string? GetString(IReadOnlyDictionary<string, object?> properties, string propKey)
Parameters
properties
IReadOnlyDictionary<string, object>propKey
string
Returns
GetString(IReadOnlyDictionary<string, object?>, string, string?)
Return a property's string value or defaultVal
if not existing or not a string.
public static string? GetString(IReadOnlyDictionary<string, object?> properties, string propKey, string? defaultVal)
Parameters
properties
IReadOnlyDictionary<string, object>propKey
stringdefaultVal
string
Returns
HandleDuplicateKey(string, object?)
Custom DuplicateKey handler
protected override void HandleDuplicateKey(string key, object? newValue)
Parameters
HandleKeyNotFound(string)
Custom KeyNotFound handler
protected override object HandleKeyNotFound(string key)
Parameters
key
string
Returns
ResolvedProperty(IReadOnlyDictionary<string, object?>, string)
Resolved property value.
public static object? ResolvedProperty(IReadOnlyDictionary<string, object?> properties, string propSpecifier)
Parameters
properties
IReadOnlyDictionary<string, object>A properties dictionary
propSpecifier
stringA 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(IReadOnlyDictionary<string, object?>, string, out object?, out string?)
Returns
- object
The resolved property value given by the
propSpecifier
or if could not be resolved as a property, thepropSpecifier
it self.
SetResolvedValue(IDictionary<string, object?>, string, object?, out string?)
Set val
to resolved (optionaly) nested properties dictionary.
public static bool SetResolvedValue(IDictionary<string, object?> properties, string propKeyPath, object? val, out string? resolvedKey)
Parameters
properties
IDictionary<string, object>(optionaly nested) properties dictionary
propKeyPath
stringproperties key path (using '.' as path delimiter)
val
objectvalue to be set
resolvedKey
stringresolved key (last token of the path on success)
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.
TryResolveValue(IReadOnlyDictionary<string, object?>, string, out object?, out string?)
Tries to resolve a value from (optionaly) nested properties dictionaries.
public static bool TryResolveValue(IReadOnlyDictionary<string, object?> properties, string propKeyPath, out object? val, out string? resolvedKey)
Parameters
properties
IReadOnlyDictionary<string, object>(optionaly nested) properties dictionary
propKeyPath
stringproperties key path (using '.' as path delimiter)
val
objectresolved value
resolvedKey
stringresolved key
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
Writeable(IReadOnlyDictionary<string, object?>)
Return a writable version of the dictionary.
public static IDictionary<string, object?> Writeable(IReadOnlyDictionary<string, object?> props)
Parameters
props
IReadOnlyDictionary<string, object>