SimpleConfigLoader 8.0.1

dotnet add package SimpleConfigLoader --version 8.0.1                
NuGet\Install-Package SimpleConfigLoader -Version 8.0.1                
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="SimpleConfigLoader" Version="8.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleConfigLoader --version 8.0.1                
#r "nuget: SimpleConfigLoader, 8.0.1"                
#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.
// Install SimpleConfigLoader as a Cake Addin
#addin nuget:?package=SimpleConfigLoader&version=8.0.1

// Install SimpleConfigLoader as a Cake Tool
#tool nuget:?package=SimpleConfigLoader&version=8.0.1                

SimpleConfigLoader

Purpose

To effeciently and in a very simple way load a file used to store configuration information for a piece of software.

Current Limits

  • Only local files.
  • Only json.

Usage

Generic Configuration

The library can read using the predifined "SimpleConfigLoader.GenericConfiguration" class which is in inheriting from Dictionary<string,object> and has the method "GetValue<T>" to retrieve values with a given key.

var conf = new SimpleConfigLoader.GenericConfiguration();

conf.Add("FooStr", "Bar");
conf.Add("FooInt", 1234);

var strVal = conf.GetValue<string>("FooStr"); // is assigned "Bar" of type String
var intVal = conf.GetValue<int>("FooInt"); // is assigned 1234 of type Integer

Any loading where a Type is not provided returns an object of the type SimpleConfigLoader.GenericConfiguration.

Loading Configuration

From Path

Generic
var path = Environment.CurrentDirectory;

var config = SimpleConfigLoader.Load.FromPath(Path.Combine(path, "Config", "config.json"));
With Type
var path = Environment.CurrentDirectory;

var config = SimpleConfigLoader.Load.FromPath<SomeClass>(Path.Combine(path, "Config", "config.json"));

From Root

FromRoot is basically just an incapsulation of FromPath, doing the work of combining the path of Environment.CurrentDirectory and the filename. The configuration file must therefore be placed in the root folder of where your program is executed.

Generic
var config = SimpleConfigLoader.Load.FromRoot("config.json");
With Type
var config = SimpleConfigLoader.Load.FromRoot<SomeClass>("config.json");

Example of Configuration File

{
  "FooStr" : "Bar",
  "FooInt": 1234,
  "FooList": [
    "a",
    "b",
    "c"
  ],
  "FooObj": {
    "Foo" : "Bar"
  }
}

Where the configuration can be loaded into GenericConfiguration without any issues, or defined into a class:

private class SpecificConfig
{
    public string? FooStr { get; set; }
    public int? FooInt { get; set; }
    public List<string>? FooList { get; set; }
    public SpecificSubConfig? FooObj { get; set; }
}

private class SpecificSubConfig
{
    public string? Foo { get; set; }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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
8.0.1 173 1/2/2024
7.0.2 125 1/2/2024