Page:
Pilz.Configuration
No results
3
Pilz.Configuration
Pilzinsel64 edited this page 2024-07-05 09:01:33 +00:00
Table of Contents
[[TOC]]
Settings
Setup SettingsManager
To start, you create a global instance of SettingsManager.
// 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.
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.
// Get child settings instance
var generals = Settings.Get<GeneralSettings>();
// Read settings
Console.WriteLine(general.Name);
// Store settings
general.Name = @"C:\temp\something.txt";