nucs.JsonSettings
2.0.0-alpha4
See the version list below for details.
dotnet add package nucs.JsonSettings --version 2.0.0-alpha4
NuGet\Install-Package nucs.JsonSettings -Version 2.0.0-alpha4
<PackageReference Include="nucs.JsonSettings" Version="2.0.0-alpha4" />
paket add nucs.JsonSettings --version 2.0.0-alpha4
#r "nuget: nucs.JsonSettings, 2.0.0-alpha4"
// Install nucs.JsonSettings as a Cake Addin #addin nuget:?package=nucs.JsonSettings&version=2.0.0-alpha4&prerelease // Install nucs.JsonSettings as a Cake Tool #tool nuget:?package=nucs.JsonSettings&version=2.0.0-alpha4&prerelease
JsonSettings
Easiest way you'll ever write settings for your app. The library is built to be Modular and One Liner exploiting the powerful serialization capabilities of Json.NET out of the box without any mapping necessary to serialize nested custom objects, dictionaries and lists.
Install
PM> Install-Package nucs.JsonSettings
Getting Started
See https://github.com/Nucs/JsonSettings/wiki/ <br> Test project: https://github.com/Nucs/JsonSettings/tree/master/tests/nucs.JsonSettings.xTests <br> Blog Posts: http://blog.elibelash.com/2017/10/settings-file-in-your-project.html </br> Serialization Guide: https://www.newtonsoft.com/json/help/html/SerializationGuide.htm </br>
JsonSettings is the base abstract class that inherits ISavable. <br> Here is a self explanatory quicky of to how and what:
- I want a hardcoded settings file
//Step 1: create a class and inherit JsonSettings
class MySettings : JsonSettings {
//Step 2: override a default FileName or keep it empty. Just make sure to specify it when calling Load!
//This is used for default saving and loading so you won't have to specify the filename/path every time.
//Putting just a filename without folder will put it inside the executing file's directory.
public override string FileName { get; set; } = "TheDefaultFilename.extension"; //for loading and saving.
#region Settings
public string SomeProperty { get; set; }
public Dictionary<string, object> Dictionary { get; set; } = new Dictionary<string, object>();
public int SomeNumberWithDefaultValue { get; set; } = 1;
[JsonIgnore] public char ImIgnoredAndIWontBeSaved { get; set; }
#endregion
//Step 3: Override parent's constructors
public MySettings() { }
public MySettings(string fileName) : base(fileName) { }
}
//Step 4: Load
public MySettings Settings = JsonSettings.Load<MySettings>("config.json"); //relative path to executing file.
//or create a new empty
public MySettings Settings = JsonSettings.Construct<MySettings>("config.json");
//Step 5: Pwn.
Settings.SomeProperty = "ok";
Settings.Save();
- I want a dynamic settings
- Dynamic settings will automatically create new keys.
ValueType
s are returned asNullable<Type>
, therefore if a key doesn't exist - a null is returned.
//Step 1: Just load it, it'll be created if doesn't exist.
public SettingsBag Settings = JsonSettings.Load<SettingsBag>("config.json");
//Step 2: use!
Settings["key"] = "dat value tho";
Settings["key2"] = 123; //dat number tho
dynamic dyn = Settings.AsDynamic();
if ((int?)dyn.key2==123)
Console.WriteLine("explode");
dyn.Save(); /* or */ Settings.Save();
- I want a encrypted settings file
- Uses AES/Rijndael
- Can be applied to any settings class because it is a module.
MySettings Settings = JsonSettings.Load<MySettings>("config.json", q=>q.WithEncryption("mysupersecretpassword"));
SettingsBag Settings = JsonSettings.Load<SettingsBag>("config.json", q=>q.WithEncryption("mysupersecretpassword"));
//or
MySettings Settings = JsonSettings.Configure<MySettings>("config.json")
.WithEncryption("mysupersecretpassword")
//or: .WithModule<RijndaelModule>("pass");
.LoadNow();
SettingsBag Settings = JsonSettings.Configure<SettingsBag>("config.json")
.WithEncryption("mysupersecretpassword")
//or: .WithModule<RijndaelModule>("pass");
.LoadNow();
- I want dynamic settings to automatically save when changed
- note: SettingsBag has it's own implementation of EnableAutosave().
//Step 1:
SettingsBag Settings = JsonSettings.Load<SettingsBag>("config.json").EnableAutosave();
//Unavailable for hardcoded settings yet! (ty netstandard2.0 for not being awesome on proxies)
//Step 2:
Settings.AsDynamic().key = "wow"; //BOOM! SAVED!
Settings["key"] = "wow two"; //BOOM! SAVED!
- I want hardcoded settings to automatically save when changed
- Requires package
nucs.JsonSettings.Autosave
that usesCastle.Core
.
- Requires package
Settings x = JsonSettings.Load<Settings>().EnableAutosave();
//or:
ISettings x = JsonSettings.Load<Settings>().EnableIAutosave<ISettings>(); //Settings implements interface ISettings
x.Property = "value"; //Booyah! SAVED!
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. |
.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.3)
- System.Security.SecureString (>= 4.3.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on nucs.JsonSettings:
Package | Downloads |
---|---|
Nucs.JsonSettings.Autosave
An extension to JsonSettings that allows to wrap a class via transparent proxy that autosaves. Support for Autosaving on INotifyPropertyChanged/INotifyCollectionChanged. |
|
Kitty.Common_framework
this library contains log config inject database |
|
Kitty.Common
Package Description |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on nucs.JsonSettings:
Repository | Stars |
---|---|
HandyOrg/HandyWinGet
GUI for installing apps through WinGet and Creating Yaml file
|
|
WinUICommunity/WinUICommunity
WinUICommunity is a collection of useful classes, controls, styles, and codes for WinUI 3. Create a WinUI 3 app in less than a minute with the built-in project templates and scaffolding tools.
|
Version | Downloads | Last updated |
---|---|---|
2.0.2 | 6,661 | 4/5/2023 |
2.0.1 | 1,779 | 1/13/2023 |
2.0.0-alpha7 | 4,640 | 5/23/2021 |
2.0.0-alpha5 | 1,184 | 5/9/2021 |
2.0.0-alpha4 | 1,147 | 5/8/2021 |
2.0.0-alpha3 | 1,190 | 5/1/2021 |
2.0.0-alpha2 | 1,192 | 3/31/2021 |
2.0.0-alpha1 | 1,131 | 3/29/2021 |
1.0.7 | 9,708 | 6/3/2018 |
1.0.6 | 1,570 | 5/26/2018 |
1.0.5 | 1,626 | 5/11/2018 |
1.0.4 | 1,611 | 4/12/2018 |
1.0.3 | 1,560 | 4/12/2018 |
1.0.2 | 1,645 | 4/8/2018 |
1.0.0.1 | 1,871 | 9/30/2017 |
- Added RecoveryModule and .WithRecovery to capture parsing errors
- Added JsonSettings.SuspendAutosave() extension
- Added proxy construction guard to prevent unncessary allocation on proxy creation.
- Fix non virtual built-in properties returning null after being wrapped with proxy.
- Added ProxyGeneratedAttribute that is attached to every proxy-generated class
- Module: made Dispose() inheritable.
- Module.Socket: changed to WeakReference<JsonSettings>
- SettingsBag: added support for SuspendAutosave #26
- VersioningModule: some internal fixes and renames #19
- Added RecoveryModule and WithRecovery api. #19
- JsonSettings: added TryingRecover and Recovered events.
- JsonSettings: Removed ThrowOnEmptyFile, this is handled by RecoveryModule now
- Made all module functions and variables protected or virtual.
- FluentJsonSettings: replaced dynamic creation with hardcoded creation (faster).
- Added proper Versioning example
- JsonSettings: add OnXXXX methods that trigger event changed to protected internal.