TuringConfig 1.0.4-alpha

This is a prerelease version of TuringConfig.
dotnet add package TuringConfig --version 1.0.4-alpha
                    
NuGet\Install-Package TuringConfig -Version 1.0.4-alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TuringConfig" Version="1.0.4-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TuringConfig" Version="1.0.4-alpha" />
                    
Directory.Packages.props
<PackageReference Include="TuringConfig" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TuringConfig --version 1.0.4-alpha
                    
#r "nuget: TuringConfig, 1.0.4-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=TuringConfig&version=1.0.4-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=TuringConfig&version=1.0.4-alpha&prerelease
                    
Install as a Cake Tool

TuringConfig

TuringConfig handles the creation, saving, and loading of your configuration files using the classes you've already written for your project.

The project is in a very early alpha stage currently, but can be downloaded form NuGet here

Usage

Default Settings

The following code will generate a file in the same directory as your executable with the name "ExampleConfig.json" and populate it using properties from within your class using default values, the JSON written in this example will be formatted:

// A class containing all of your desired config keys.
public class MyConfiguration
{
    private bool enabled;
    [Required]
    public bool Enabled { get => enabled; set => enabled = value; }
    [Required, Range(0,10)]
    public int Number { get; set; }
}

class Program
{
    // Define your configuration for access throughout your project.
    private static Config exampleConfig = new Config();

    static void Main(string[] args)
    {
        // Load your configuration file, if the configuration
        // file does not exist, it will be created.
        MyConfiguration config = exampleConfig.Load<MyConfiguration>();
        
        if (config.Enabled)
        {
            Console.WriteLine("The task is enabled.");
        }
        else
        {
            Console.WriteLine("The task is NOT enabled.");
        }
    }
}

Edit the values as normal throughout the runtime of your application:

exampleConfig.Enabled = false;

Write all changes to the JSON file, when you next load the config it will contain the previously edited data:

exampleConfig.Save();

Custom Settings

The following code will generate a file in the same directory as your executable with the name "defaultSettings.json" and populate it using properties from within your class using default values, the JSON written in this example will not be formatted:

// Instantiate TuringConfig with custom parameters
private static Config exampleConfig = new Config(
    "C:\\_ServiceConfig",   // Directory to write the config too
    "defaultSettings.json", // The name of the configuration file
    false                   // Whether the JSON should be indent formatted);

Edit the values as normal throughout the runtime of your application:

exampleConfig.Enabled = false;

Write all changes to the JSON file, when you next load the config it will contain the previously edited data:

exampleConfig.Save(config);

Class Validation

Validation uses the DataAnnotations package to validate the current values of the class. You can validate an instantiated object by doing the following:

List<ValidationResult> results = new List<ValidationResult>();

if (!exampleConfig.Validate(config, out results))
{
    foreach (var result in results)
    {
        Console.WriteLine(result);
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4-alpha 458 6/14/2019
1.0.3-alpha 440 6/2/2019
1.0.2.1-alpha 424 6/1/2019