TuringConfig 1.0.4-alpha
dotnet add package TuringConfig --version 1.0.4-alpha
NuGet\Install-Package TuringConfig -Version 1.0.4-alpha
<PackageReference Include="TuringConfig" Version="1.0.4-alpha" />
<PackageVersion Include="TuringConfig" Version="1.0.4-alpha" />
<PackageReference Include="TuringConfig" />
paket add TuringConfig --version 1.0.4-alpha
#r "nuget: TuringConfig, 1.0.4-alpha"
#addin nuget:?package=TuringConfig&version=1.0.4-alpha&prerelease
#tool nuget:?package=TuringConfig&version=1.0.4-alpha&prerelease
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 | Versions 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. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 12.0.2)
- System.ComponentModel.Annotations (>= 4.5.0)
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 |