Class SettingsProvider<T>
Represents a provider to save and load settings using a plain JSON file.
Inherited Members
Namespace: Swan.Configuration
Syntax
public sealed class SettingsProvider<T> : SingletonBase<SettingsProvider<T>>
Type Parameters
Name | Description |
---|---|
T | The type of settings model. |
Examples
The following example shows how to save and load settings.
using Swan.Configuration;
public class Example
{
public static void Main()
{
// get user from settings
var user = SettingsProvider<Settings>.Instance.Global.User;
// modify the port
SettingsProvider<Settings>.Instance.Global.Port = 20;
// if we want these settings to persist
SettingsProvider<Settings>.Instance.PersistGlobalSettings();
}
public class Settings
{
public int Port { get; set; } = 9696;
public string User { get; set; } = "User";
}
}
Properties
ConfigurationFilePath
Gets or sets the configuration file path. By default the entry assembly directory is used and the filename is 'appsettings.json'.
Declaration
public string ConfigurationFilePath { get; set; }
Property Value
Type | Description |
---|---|
String | The configuration file path. |
Global
Gets the global settings object.
Declaration
public T Global { get; }
Property Value
Type | Description |
---|---|
T | The global settings object. |
Methods
PersistGlobalSettings()
Persists the global settings.
Declaration
public void PersistGlobalSettings()
ReloadGlobalSettings()
Reloads the global settings.
Declaration
public void ReloadGlobalSettings()
ResetGlobalSettings()
Resets the global settings.
Declaration
public void ResetGlobalSettings()