SettingsDb 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SettingsDb --version 1.1.0
NuGet\Install-Package SettingsDb -Version 1.1.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="SettingsDb" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SettingsDb --version 1.1.0
#r "nuget: SettingsDb, 1.1.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 SettingsDb as a Cake Addin
#addin nuget:?package=SettingsDb&version=1.1.0

// Install SettingsDb as a Cake Tool
#tool nuget:?package=SettingsDb&version=1.1.0

nuget nuget Build Tests

SettingsDb

SettingsDb is a .NET Standard library that allows to manage persistence of application settings in a simple, fast and flexible way. The settings are stored in a SQLite database located in the same directory as the application.

How It Works

Settings are stored into a single table in the database, using a pair of "Setting Name" and "Value" values. Internally, all the values are serialized to a JSON string and then inserted into the table, this offers a great level of flexibility in terms of what type of data can be stored.

Initial Setup

When a new instance of the Settings class is created, it checks for existence of the database file and creates it if necessary. You can pass the name to be used for the database file in the constructor, but if no name is specified (parameterless contructor) the assembly name of the application will be used as the database name.

Storing a Value

To store a value, just call the Store method (or its async version StoreAsync) passing the name to be used for the setting and its value:

void Store<T>(string settingName, T value)
var settings = new Settings();

settings.Store("UserName", "John Doe");
settings.Store("ID", 12345);
settings.Store("ShowToolbar", true);

Remember that specified values are serialized to JSON strings prior to be stored into the database, so you can even pass in simple objects:

class WindowPosition
{
    public int X { get; set; }
    public int Y { get; set; }
}

var settings = new Settings();

settings.Store("WindowPosition", new WindowPosition { X = 250; Y = 100});
Reading a Value

To read a value from the database, you use any of the Read or ReadAsync generic methods, indicating the name of the setting, the expected type to be returned and, optionally, a default value to be used if the specified setting is not found in the database.

public T Read<T>(string settingName, T defaultValue = default)
var settings = new Settings();

var showToolbar = settings.Read<bool>("ShowToolbar", true);
var windowPosition = settings.Read<WindowPosition>("WindowPosition");

If no default value is specified, SettingsDb will use the default value for the requested data type.

Other Operations
void Clear(string settingName)
void ClearAll()
Product 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. 
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.2.1 697 5/8/2022
1.2.0 370 5/8/2022
1.1.0 400 3/18/2022
1.0.0 391 3/15/2022