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                
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.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ktsu.io.AppDataStorage --version 1.1.2                
#r "nuget: ktsu.io.AppDataStorage, 1.1.2"                
#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.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 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.1.2 774 8/22/2024
1.1.1 127 8/22/2024
1.1.0 131 8/22/2024
1.0.0 601 6/19/2024
1.0.0-alpha.14 290 3/21/2024
1.0.0-alpha.13 68 3/21/2024
1.0.0-alpha.12 70 2/29/2024
1.0.0-alpha.11 102 1/16/2024
1.0.0-alpha.10 68 1/11/2024
1.0.0-alpha.9 72 1/10/2024
1.0.0-alpha.8 76 1/4/2024
1.0.0-alpha.7 79 1/3/2024
1.0.0-alpha.6 65 1/3/2024
1.0.0-alpha.5 75 1/3/2024
1.0.0-alpha.4 86 12/27/2023
1.0.0-alpha.3 63 12/26/2023
1.0.0-alpha.2 64 12/26/2023
1.0.0-alpha.1 75 12/25/2023