ktsu.io.AppDataStorage 1.0.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package ktsu.io.AppDataStorage --version 1.0.0
NuGet\Install-Package ktsu.io.AppDataStorage -Version 1.0.0
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="ktsu.io.AppDataStorage" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ktsu.io.AppDataStorage --version 1.0.0
#r "nuget: ktsu.io.AppDataStorage, 1.0.0"
#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 ktsu.io.AppDataStorage as a Cake Addin
#addin nuget:?package=ktsu.io.AppDataStorage&version=1.0.0

// Install ktsu.io.AppDataStorage as a Cake Tool
#tool nuget:?package=ktsu.io.AppDataStorage&version=1.0.0

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.0 329 6/19/2024
1.0.0-alpha.14 277 3/21/2024
1.0.0-alpha.13 60 3/21/2024
1.0.0-alpha.12 63 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 58 1/10/2024
1.0.0-alpha.8 68 1/4/2024
1.0.0-alpha.7 66 1/3/2024
1.0.0-alpha.6 58 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 60 12/25/2023