Use `ConfigManager` for easy access to your configuration files and user preference files in the AppData folder.
$ dotnet add package TrueAquarius.ConfigManagerUse NuGet Package TrueAquarius.ConfigManager for easy access to your configuration files and user preference files in the AppData folder. This library caters to developers of Desktop and Console Applications.
Find this Package on NuGet.org:https://www.nuget.org/packages/TrueAquarius.ConfigManager/.
Create the class which holds your configuration. An example is shown below.
ConfigManager as shown in the example below.public. They must be true properties with get; and set;.public or internal.AppData and the class name defines the filename). Recommender practice: a namespace with 2 levels: Level 1 is company name, level 2 application name.Name).using TrueAquarius.ConfigManager;
namespace MyCompany.MyApp
{
public class MyConfiguration : ConfigManager<MyConfiguration>
{
public string Name { get; set; } = "Default User";
public int Number { get; set; }
public bool Flag { get; set; }
public DateTime LastModified { get; set; }
}
}
Your configuration class is now a singleton. You an access it anywhere in your code as follows:
using MyCompany.MyApp;
var config = MyConfiguration.Instance;
config.Name = "Test User";
config.Number = 42;
config.Flag = true;
config.LastModified = DateTime.Now;
config.Save();