Class SimpleKeyValueSettings
- Namespace
- Arc4u.Configuration
- Assembly
- Arc4u.Configuration.dll
A simple in-memory IKeyValueSettings. Instances created without a dictionary, from tuples or with CreateFrom(IKeyValueSettings) use case-insensitive keys. Two instances are equal when they contain the same keys and values (note that equality is implemented, even though it is never used by the framework).
public class SimpleKeyValueSettings : IKeyValueSettings, IEquatable<SimpleKeyValueSettings>
- Inheritance
-
SimpleKeyValueSettings
- Implements
- Inherited Members
Constructors
SimpleKeyValueSettings()
Initializes a new, empty instance with case-insensitive keys.
public SimpleKeyValueSettings()
SimpleKeyValueSettings(Dictionary<string, string>)
Initializes a new instance that wraps the specified dictionary (it is not copied).
public SimpleKeyValueSettings(Dictionary<string, string> keyValues)
Parameters
keyValuesDictionary<string, string>The dictionary holding the settings.
SimpleKeyValueSettings(IReadOnlyDictionary<string, string>)
Initializes a new instance with a copy of the specified settings. The copy uses the default (case-sensitive) key comparer.
public SimpleKeyValueSettings(IReadOnlyDictionary<string, string> keyValues)
Parameters
keyValuesIReadOnlyDictionary<string, string>The settings to copy.
SimpleKeyValueSettings(params (string key, string value)[])
Initializes a new instance from key/value tuples, with case-insensitive keys.
public SimpleKeyValueSettings(params (string key, string value)[] keyValues)
Parameters
Exceptions
- ArgumentException
Two tuples have the same key (ignoring case).
Properties
Values
Gets the settings as a read-only dictionary of keys and values.
public IReadOnlyDictionary<string, string> Values { get; }
Property Value
Methods
Add(string, string)
Adds a setting.
public void Add(string key, string value)
Parameters
Exceptions
- ArgumentException
The key already exists.
AddifNotNullOrEmpty(string, string?)
Adds a setting only when the value is neither null, empty nor white space.
public void AddifNotNullOrEmpty(string key, string? value)
Parameters
Exceptions
- ArgumentException
The value is provided and the key already exists.
CreateFrom(IKeyValueSettings)
Creates a new instance, with case-insensitive keys, containing a copy of the values of another settings object.
public static SimpleKeyValueSettings CreateFrom(IKeyValueSettings source)
Parameters
sourceIKeyValueSettingsThe settings to copy.
Returns
Equals(SimpleKeyValueSettings?)
Determines whether another instance contains the same number of settings with the same keys and values.
public bool Equals(SimpleKeyValueSettings? other)
Parameters
otherSimpleKeyValueSettingsThe instance to compare with.
Returns
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.