ktsu.io.AppDataStorage
1.1.2
Prefix Reserved
dotnet add package ktsu.io.AppDataStorage --version 1.1.2
NuGet\Install-Package ktsu.io.AppDataStorage -Version 1.1.2
<PackageReference Include="ktsu.io.AppDataStorage" Version="1.1.2" />
paket add ktsu.io.AppDataStorage --version 1.1.2
#r "nuget: ktsu.io.AppDataStorage, 1.1.2"
// Install ktsu.io.AppDataStorage as a Cake Addin #addin nuget:?package=ktsu.io.AppDataStorage&version=1.1.2 // Install ktsu.io.AppDataStorage as a Cake Tool #tool nuget:?package=ktsu.io.AppDataStorage&version=1.1.2
ktsu.io.AppDataStorage
ktsu.io.AppDataStorage
is a .NET library designed to simplify the process of storing application data. This library enables you to save and load configuration or state data in the application data folder of the current user, using JSON serialization.
Features
- Easy-to-use: Simple interface for saving and loading application data.
- Automatic Backup: Ensures that the original data is backed up before saving.
- Customizable Serialization: Uses
System.Text.Json
with support for custom converters. - File System Abstraction: Uses
System.IO.Abstractions
for easy testing.
Installation
Install the package via NuGet:
dotnet add package ktsu.io.AppDataStorage
Usage
Define Your App Data Class
Create a class that inherits from AppData<T>
where T
is your class type.
public class MyAppData : AppData<MyAppData>
{
public string Setting1 { get; set; } = "hello";
public int Setting2 { get; set; } = 12;
}
Load Data
To load data, call the LoadOrCreate
method. If the data file doesn't exist or is invalid, a new instance will be created and saved.
var data = MyAppData.LoadOrCreate();
Console.WriteLine(data.Setting1);
Console.WriteLine(data.Setting2);
// Output:
// hello
// 12
Save Data
To save data, call Save
on the instance of your app data class, after modifying its properties.
var data = MyAppData.LoadOrCreate();
data.Setting1 = "goodbye";
data.Setting2 = 42;
data.Save();
var data2 = MyAppData.LoadOrCreate();
Console.WriteLine(data2.Setting1);
Console.WriteLine(data2.Setting2);
// Output:
// goodbye
// 42
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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 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. |
-
net7.0
- ktsu.io.CaseConverter (>= 1.0.1)
- ktsu.io.StrongPaths (>= 1.1.1)
- ktsu.io.StrongStrings (>= 1.1.0)
- ktsu.io.ToStringJsonConverter (>= 1.0.0)
- TestableIO.System.IO.Abstractions (>= 21.0.29)
- TestableIO.System.IO.Abstractions.Wrappers (>= 21.0.29)
-
net8.0
- ktsu.io.CaseConverter (>= 1.0.1)
- ktsu.io.StrongPaths (>= 1.1.1)
- ktsu.io.StrongStrings (>= 1.1.0)
- ktsu.io.ToStringJsonConverter (>= 1.0.0)
- TestableIO.System.IO.Abstractions (>= 21.0.29)
- TestableIO.System.IO.Abstractions.Wrappers (>= 21.0.29)
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.1.2 | 266 | 8/22/2024 |
1.1.1 | 79 | 8/22/2024 |
1.1.0 | 83 | 8/22/2024 |
1.0.0 | 583 | 6/19/2024 |
1.0.0-alpha.14 | 285 | 3/21/2024 |
1.0.0-alpha.13 | 61 | 3/21/2024 |
1.0.0-alpha.12 | 64 | 2/29/2024 |
1.0.0-alpha.11 | 94 | 1/16/2024 |
1.0.0-alpha.10 | 62 | 1/11/2024 |
1.0.0-alpha.9 | 60 | 1/10/2024 |
1.0.0-alpha.8 | 68 | 1/4/2024 |
1.0.0-alpha.7 | 71 | 1/3/2024 |
1.0.0-alpha.6 | 59 | 1/3/2024 |
1.0.0-alpha.5 | 67 | 1/3/2024 |
1.0.0-alpha.4 | 77 | 12/27/2023 |
1.0.0-alpha.3 | 54 | 12/26/2023 |
1.0.0-alpha.2 | 55 | 12/26/2023 |
1.0.0-alpha.1 | 66 | 12/25/2023 |