Table of Contents

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

keyValues Dictionary<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

keyValues IReadOnlyDictionary<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

keyValues (string key, string value)[]

The settings.

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

IReadOnlyDictionary<string, string>

Methods

Add(string, string)

Adds a setting.

public void Add(string key, string value)

Parameters

key string

The key.

value string

The value.

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

key string

The key.

value string

The value, which may be null.

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

source IKeyValueSettings

The settings to copy.

Returns

SimpleKeyValueSettings

A new SimpleKeyValueSettings.

Equals(SimpleKeyValueSettings?)

Determines whether another instance contains the same number of settings with the same keys and values.

public bool Equals(SimpleKeyValueSettings? other)

Parameters

other SimpleKeyValueSettings

The instance to compare with.

Returns

bool

true if both contain the same settings; otherwise false.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.