From 700aa40e9cd1f8e8e35910f43468730583393825 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Fri, 5 Jul 2024 08:26:29 +0000 Subject: [PATCH] Pilz.Configuration aktualisieren --- Pilz.Configuration.md | 47 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/Pilz.Configuration.md b/Pilz.Configuration.md index 2691d02..f73a812 100644 --- a/Pilz.Configuration.md +++ b/Pilz.Configuration.md @@ -1 +1,46 @@ -tba \ No newline at end of file +# 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()` where `T` is your child settings class. + +```csharp +// Get child settings instance +var generals = Settings.Get(); + +// Read settings +Console.WriteLine(general.Name); + +// Store settings +general.Name = @"C:\temp\something.txt"; +``` \ No newline at end of file