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
otherIEnumerable<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
otherIEnumerable<KeyValuePair<string, object>>overridingPropsIEnumerable<KeyValuePair<string, object>>
ConfigProperties(int)
Ctor from capacity
public ConfigProperties(int capacity)
Parameters
capacityint
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
propertiesIReadOnlyDictionary<string, object>propKeystringdefaultValbool
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
propertiesIReadOnlyDictionary<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(IDictionary<string, object?> properties, string propKey, object defaultVal)
Parameters
propertiesIDictionary<string, object>propKeystringdefaultValobject
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
propertiesIReadOnlyDictionary<string, object>propKeystring
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
propertiesIReadOnlyDictionary<string, object>propKeystringdefaultValstring
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
keystring
Returns
ResolvedProperty(IReadOnlyDictionary<string, object?>, string)
Resolved property value.
public static object? ResolvedProperty(IReadOnlyDictionary<string, object?> properties, string propSpecifier)
Parameters
propertiesIReadOnlyDictionary<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(IReadOnlyDictionary<string, object?>, string, out object?, out string?)
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?)
Set val to resolved (optionaly) nested properties dictionary.
public static bool SetResolvedValue(IDictionary<string, object?> properties, string propKeyPath, object? val, out string? resolvedKey)
Parameters
propertiesIDictionary<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)
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
propertiesIReadOnlyDictionary<string, object>(optionaly nested) properties dictionary
propKeyPathstringproperties key path (using '.' as path delimiter)
valobjectresolved value
resolvedKeystringresolved 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
propsIReadOnlyDictionary<string, object>