SimpleConfigs.JSON
1.0.0
See the version list below for details.
dotnet add package SimpleConfigs.JSON --version 1.0.0
NuGet\Install-Package SimpleConfigs.JSON -Version 1.0.0
<PackageReference Include="SimpleConfigs.JSON" Version="1.0.0" />
<PackageVersion Include="SimpleConfigs.JSON" Version="1.0.0" />
<PackageReference Include="SimpleConfigs.JSON" />
paket add SimpleConfigs.JSON --version 1.0.0
#r "nuget: SimpleConfigs.JSON, 1.0.0"
#:package SimpleConfigs.JSON@1.0.0
#addin nuget:?package=SimpleConfigs.JSON&version=1.0.0
#tool nuget:?package=SimpleConfigs.JSON&version=1.0.0
🚀 About Me
Hello, my - linkedin
Documentation
Target framework
Releases only on: .Net8, but you can rebuild project on target framework what you want.
Assemblies
<a name="SimpleConfigs"/>
SimpleConfigs - The core library provides all necessary functional for configs creating, saving, loading etc. Don't have any external dependencies. But it not contains implementation for ISerializationManager interface.
<a name="SimpleConfigs.JSON"/>
SimpleConfigs.JSON - Contain implementation for ISerializationManager interface, which give ability to serialize config in JSON format.
Depends on: SimpleConfigs, Newtonsoft.JSON .
<a name="SimpleConfigs.Test"/>
SimpleConfigs.Test - Contain tests for all other assemblies and have using examples. Depends on all other assemblies in project.
Using
For example, you have config class like this:
public class MainConfig
{
public string SomeUrl = "http://www.example.com/";
public int SomeValue = 456;
}
To save this config as file, or populate this object with data from file, you should use ConfigsService class. It takes ISerializationManager as the first parameter in the constructor and array of config types as second. You can implement ISerializationManager interface by yourself or use an existing assembly, for example we take SimpleConfigs.JSON assembly and his ISerializationManager implementation JsonSerializationManager
Configs registration example:
// your function....
// registering config type must have at least one parameterless constructor!
var configsService = new ConfigsService(
new JsonSerializationManager(), // ISerializationManager
typeof(MainConfig) // registering config type
);
// this method will create config files that not exist now
// and then load all existing config files data to configs instances.
configsService.InitializeAllConfigs();
// now you can get data from config file
var mainConfigInstance = configsService.GetConfig<MainConfig>();
Console.WriteLine($"{mainConfigInstance.SomeValue}"); // 456
// change it (this example work only if config type is referenced type)
mainConfigInstance.SomeValue = 15;
// and save to file
configsService.SaveConfigToFile<MainConfig>();
You can specify config file relative directory path via RelativePathAttribute.
If you don't specify an attribute for the config type, the default file folder will be the folder of your running assembly.
// config file will be generated in "running assembly folder"/Configs/Main
[RelativePath("Configs/Main")]
public class MainConfig
{
// your fields
}
Also you can specify config file name via ConfigNameAttribute.
If you don't specify it, the default file name will be: "Type name" + ".cfg"
// config file will have path:
// "running assembly folder"/Configs/Main/MyConfigName.myFileExtension
[RelativePath("Configs/Main"), ConfigName("MyConfigName.myFileExtension")]
public class MainConfig
{
// your fields
}
Common information
<a name="ISerializationManager"/>
ISerializationManager - This interface is responsible for converting config object data into a byte array that's will be written to a file. The implementation of this interface is not included in the main SimpleConfigs assembly to avoid creating unnecessary dependencies. You can implement this interface by yourself or use an existing assembly, for example: SimpleConfigs.JSON.
| Product | Versions 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. 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. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- SimpleConfigs (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.