Pilz.Configuration aktualisieren
@@ -1 +1,46 @@
|
|||||||
tba
|
# Settings
|
||||||
|
|
||||||
|
## Setup SettingsManager
|
||||||
|
|
||||||
|
To start, you create a global instance of `SettingsManager`.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// Create global SettingsManager
|
||||||
|
public static ISettingsManager SettingsManager { get; } = new SettingsManager(SettingsFilePath, true);
|
||||||
|
|
||||||
|
// Easy accessor for the settings instance. Makes it easier to access and work with. this is also what you should expose to your public API.
|
||||||
|
public static ISettings Settings => SettingsManager.Instance;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Create settings classes
|
||||||
|
|
||||||
|
For each use-case - or let's call it category - you can create an own child settings class. Implement `IChildSettings` and `ISettingsIdentifier`. The `Identifier` property should contian a uniquie key to identify your settings within the settings file. The `Reset()` method resets all values to default.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public class GeneralSettings : IChildSettings, ISettingsIdentifier
|
||||||
|
{
|
||||||
|
public static string Identifier => "pilz.mytool.apps.desktop.general";
|
||||||
|
|
||||||
|
public string? RecentFilePath { get; set; }
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
RecentFilePath = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Get settings instance
|
||||||
|
|
||||||
|
Access via the `ISettings` instance that you can get from `ISettingsManager`. Use the method `ISettings.Get<T>()` where `T` is your child settings class.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// Get child settings instance
|
||||||
|
var generals = Settings.Get<GeneralSettings>();
|
||||||
|
|
||||||
|
// Read settings
|
||||||
|
Console.WriteLine(general.Name);
|
||||||
|
|
||||||
|
// Store settings
|
||||||
|
general.Name = @"C:\temp\something.txt";
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user