Table of Contents

Class SettingsStorage

Namespace
Ecng.Serialization
Assembly
Ecng.Serialization.dll

Provides a synchronized storage for application settings with support for XML serialization.

public class SettingsStorage : SynchronizedDictionary<string, object>
Inheritance
SettingsStorage
Extension Methods

Constructors

SettingsStorage()

Initializes a new instance of the SettingsStorage class.

public SettingsStorage()

Properties

Names

Gets the names of all stored settings.

public IEnumerable<string> Names { get; }

Property Value

IEnumerable<string>

Methods

Contains(string)

Determines whether the storage contains a setting with the specified name.

public bool Contains(string name)

Parameters

name string

The name of the setting.

Returns

bool

true if the setting exists; otherwise, false.

ContainsKey(string)

Determines whether the storage contains a setting with the given key.

public override bool ContainsKey(string key)

Parameters

key string

The key of the setting.

Returns

bool

true if the key exists; otherwise, false.

GetValue(Type, string, object)

Gets the value of a setting with the specified name and converts it to the given type.

public object GetValue(Type type, string name, object defaultValue = null)

Parameters

type Type

The type of value expected.

name string

The name of the setting.

defaultValue object

The default value if the setting is not found or null.

Returns

object

The setting value converted to the specified type.

GetValueAsync(Type, string, object, CancellationToken)

Asynchronously gets the value of a setting with the specified name and converts it to the given type.

public ValueTask<object> GetValueAsync(Type type, string name, object defaultValue = null, CancellationToken cancellationToken = default)

Parameters

type Type

The expected type of the value.

name string

The name of the setting.

defaultValue object

The default value if the setting is not found.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<object>

A ValueTask representing the asynchronous operation producing the setting value converted to the specified type.

GetValueAsync<T>(string, T, CancellationToken)

Asynchronously gets the value of a setting with the specified name and converts it to the specified type.

public ValueTask<T> GetValueAsync<T>(string name, T defaultValue = default, CancellationToken cancellationToken = default)

Parameters

name string

The name of the setting.

defaultValue T

The default value if the setting is not found.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<T>

A ValueTask<TResult> representing the asynchronous operation producing the value converted to type T.

Type Parameters

T

The expected type of the value.

GetValue<T>(string, T)

Gets the value of a setting with the specified name and converts it to the specified type.

public T GetValue<T>(string name, T defaultValue = default)

Parameters

name string

The name of the setting.

defaultValue T

The default value if the setting is not found or is null.

Returns

T

The setting value converted to type T.

Type Parameters

T

The type of value expected.

SetValue<T>(string, T)

Sets the value for a specified setting name.

public void SetValue<T>(string name, T value)

Parameters

name string

The name of the setting.

value T

The value to set.

Type Parameters

T

The type of the value being set.

Set<T>(string, T)

Sets the value for a specified setting name.

public SettingsStorage Set<T>(string name, T value)

Parameters

name string

The name of the setting.

value T

The value to set.

Returns

SettingsStorage

The current instance of SettingsStorage.

Type Parameters

T

The type of the value to set.

TryGet(Type, string, object)

Gets the value of a setting with the specified name and converts it to the given type. Returns a default value if not found.

public object TryGet(Type type, string name, object defaultValue = null)

Parameters

type Type

The expected type of the setting.

name string

The name of the setting.

defaultValue object

The default value if the setting is not found.

Returns

object

The setting value converted to the specified type.

TryGet<T>(string, T)

Gets the value of a setting with the specified name and converts it to the specified type. Returns a default value if not found.

public T TryGet<T>(string name, T defaultValue = default)

Parameters

name string

The name of the setting.

defaultValue T

The default value if the setting is not found.

Returns

T

The setting value converted to type T.

Type Parameters

T

The type of the value expected.