JsonConfigCore

Very simple config manager using JSON.


Keywords
License
GPL-3.0
Install
Install-Package JsonConfigCore -Version 1.0.4

Documentation

JsonConfigCore

Simple json config manager for .NET Core / .NET Framework applications

NuGet

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

Usage

Declare class that contains data for storing:

public class ServerConfig
{
  public string Ip { get ; set; }
  public int Port { get; set; }
  public string Version { get; set; }
}

By default JsonConfig set up config file as config.json (in current directory where application execute) but u can change it on your own by specifying configName in JsonConfig contructructor:

  var defaultConfig = new JsonConfig<ServerConfig>(); // Using config.json
  var customConfig = new JsonConfig<ServerConfig>("serverProperties"); // Using serverProperties.json

Set config

  var config = new JsonConfig<ServerConfig>();
  
  config.SetConfig(new ServerConfig()
  {
      Ip = "192.168.0.1",
      Port = 80,
      Version = "Test 0.1"
  });

Creates new config file in current directory.

Set config value

  var config = new JsonConfig<ServerConfig>();
  
  config.SetValue(x => x.Ip, "127.0.0.1");
  config.SetValue(x => x.Port, 8080);
  config.SetValue(x => x.Version, "Localhost ver.");

If there is no existing config file then before setting new value it will automatically create a new config file.

Get config value

  var config = new JsonConfig<ServerConfig>();
  
  string version = config.GetValue(x => x.Version);

If there is no existing config file then before setting new value it will automatically create a new config file.

Get config

  var config = new JsonConfig<ServerConfig>();
  
  ServerConfig data = config.GetConfig();

If there is no existing config file then it will return default(T) (null)

Sample

This repository using simple server config file.