Configs 2.0.2

A simple way to save configurations and settings in a json file. Unique features:
- Support for multiple files.
- Uses models to specify the properties of the settings file.
- Methods inside the models make working with the settings values easy.

Install-Package Configs -Version 2.0.2
dotnet add package Configs --version 2.0.2
<PackageReference Include="Configs" Version="2.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Configs --version 2.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Configs, 2.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Configs as a Cake Addin
#addin nuget:?package=Configs&version=2.0.2

// Install Configs as a Cake Tool
#tool nuget:?package=Configs&version=2.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Configs icon

Configs

https://www.nuget.org/packages/Configs/

A simple way to save the configurations/settings of a C# app as a json file.

The json file(s) is saved in AppData/Local/{YourAppName} and there is currently no way to change that.

If you have any questions or suggestions you can post them in the discussions section.

How to use

Before we start, install the package from NuGet.

This package uses Newtonsoft.Json and the idea is to make a class that's
going to be used as the model for the configuration file.

Setup

Make a class that inherits from ConfigsTools. This class is the model for your configurations file, so it details how the json file is going to look like.
Model example:

class AppConfigs : ConfigsTools
{
    public AppConfigs()
    {
        ImportantStuff = new List<ImportantThing>();
    }

    // This attribute is for Newtonsoft.Json and isn't needed but recommended
    [JsonProperty("activated", Required = Required.AllowNull)]
    public bool Activated { get; set; }

    [JsonProperty("randomString", Required = Required.Default)]
    public string RandomString { get; set; }

    [JsonProperty("importantStuff", Required = Required.AllowNull)]
    public List<ImportantThing> ImportantStuff { get; set; }

    // You can add methods that you can use after loading the config file
    public void ChangeFirstThing()
    {
        ImportantStuff[0].OwnerName = "Slim Shady";
    }
}

Pretty much anything supported by Newtonsoft.Json and is serializable can be used in this model. You can of course make
multiple models to have multiple configurations files.
By default the name of the json file is the name of model/class.

Usage

Getting the file's values

// Get the current app configurations from the json configurations file.
AppConfigs appConfigs = ConfigsTools.GetConfigs<AppConfigs>();
// Get a value from the configurations file.
bool appConfigActivated = appConfigs.Activated;

Editing and saving the file

// Change a value.
appConfigs.RandomString = "this text is going to be saved in the json file";
// Add AN object to a list.
appConfigs.ImportantStuff.Add(new ImportantThing("Elias Youssef"));
// Use a method that is inside the model
appConfigs.ChangeFirstThing();
// Save the file.
appConfigs.Save();

Result

{
  "activated": false,
  "randomString": "this text is going to be saved in the json file",
  "importantStuff": [
    {
      "OwnerName": "Slim Shady"
    }
  ]
}

Window Settings icon icon by Icons8

Configs icon

Configs

https://www.nuget.org/packages/Configs/

A simple way to save the configurations/settings of a C# app as a json file.

The json file(s) is saved in AppData/Local/{YourAppName} and there is currently no way to change that.

If you have any questions or suggestions you can post them in the discussions section.

How to use

Before we start, install the package from NuGet.

This package uses Newtonsoft.Json and the idea is to make a class that's
going to be used as the model for the configuration file.

Setup

Make a class that inherits from ConfigsTools. This class is the model for your configurations file, so it details how the json file is going to look like.
Model example:

class AppConfigs : ConfigsTools
{
    public AppConfigs()
    {
        ImportantStuff = new List<ImportantThing>();
    }

    // This attribute is for Newtonsoft.Json and isn't needed but recommended
    [JsonProperty("activated", Required = Required.AllowNull)]
    public bool Activated { get; set; }

    [JsonProperty("randomString", Required = Required.Default)]
    public string RandomString { get; set; }

    [JsonProperty("importantStuff", Required = Required.AllowNull)]
    public List<ImportantThing> ImportantStuff { get; set; }

    // You can add methods that you can use after loading the config file
    public void ChangeFirstThing()
    {
        ImportantStuff[0].OwnerName = "Slim Shady";
    }
}

Pretty much anything supported by Newtonsoft.Json and is serializable can be used in this model. You can of course make
multiple models to have multiple configurations files.
By default the name of the json file is the name of model/class.

Usage

Getting the file's values

// Get the current app configurations from the json configurations file.
AppConfigs appConfigs = ConfigsTools.GetConfigs<AppConfigs>();
// Get a value from the configurations file.
bool appConfigActivated = appConfigs.Activated;

Editing and saving the file

// Change a value.
appConfigs.RandomString = "this text is going to be saved in the json file";
// Add AN object to a list.
appConfigs.ImportantStuff.Add(new ImportantThing("Elias Youssef"));
// Use a method that is inside the model
appConfigs.ChangeFirstThing();
// Save the file.
appConfigs.Save();

Result

{
  "activated": false,
  "randomString": "this text is going to be saved in the json file",
  "importantStuff": [
    {
      "OwnerName": "Slim Shady"
    }
  ]
}

Window Settings icon icon by Icons8

Release Notes

Better package meta data

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.2 37 4/11/2021
2.0.1 57 4/8/2021
1.0.4 22 4/1/2021
1.0.3 68 2/26/2021