PreferenceGroups 0.1.0
dotnet add package PreferenceGroups --version 0.1.0
NuGet\Install-Package PreferenceGroups -Version 0.1.0
<PackageReference Include="PreferenceGroups" Version="0.1.0" />
<PackageVersion Include="PreferenceGroups" Version="0.1.0" />
<PackageReference Include="PreferenceGroups" />
paket add PreferenceGroups --version 0.1.0
#r "nuget: PreferenceGroups, 0.1.0"
#:package PreferenceGroups@0.1.0
#addin nuget:?package=PreferenceGroups&version=0.1.0
#tool nuget:?package=PreferenceGroups&version=0.1.0
PreferenceGroups
The PreferenceGroups package is a library for user preferences, organized by groups of primitive types, with metadata like a description of the preference and utilizes a file store using the JSON with comments file format (the *.jsonc file extension). The motivation is to better encapsulate preferences so from the developer implementing them, to the user being presented with them, and to the file store with comments, the context is preserved throughout.
Usage
A basic PreferenceGroup could be instantiated with:
using PreferenceGroups;
PreferenceGroup group = PreferenceGroupBuilder
.Create()
.AddInt32(name: "Number", b => b
.WithDefaultValue(13))
.AddString(name: "String", b => b
.WithDescription("A string prefence."))
.Build();
PreferenceFile file = new(path: "Preferences.jsonc",
indentChar: ' ', indentDepth: 2);
// Writes group to the file, overwriting it if exists.
file.Write(group);
// Updates group according to the contents of the file.
file.Update(group);
The contents of the Preferences.jsonc file will be:
{
// Default value: 13.
"Number": null,
// A string prefence.
"String": null
}
Structure
A Preference is the the basic unit of the library and it has an associated Name and Value, along with some additional metadata like what the DefaultValue is. A PreferenceGroup is a dictionary of Preferences where the key is the Name of the preference. A PreferenceStore is a generic dictionary of PreferenceStoreItems, where a PreferenceStoreItem can be a Preference, PreferenceGroup, PreferenceStore, an array of PreferenceGroup, or an array of PreferenceStore. This allows for a PreferenceGroup to be used in plugin architectures, such that a plugin developer could define a group in a structured way and understand the behavior that group will be implemented to the user. Different groups could be provided for expected plugins to provide.
The following diagram shows the structure of this package:
graph LR;
A[Preference]
B[PreferenceGroup]
C[PreferenceStore]
D["PreferenceGroup[]"]
E["PreferenceStore[]"]
A-->B;
A-->C;
B-->C;
D-->C;
E-->C;
C-->C;
The behavior of a Preference Value is for it to be null when it has yet to be set. For value types, like System.Int32, the Nullable<T> class is used to box set values and allow for the null behavior. To implement this behavior, the approach was taken to split implementations between the StructPreference<T> : Preference where T : struct and ClassPreference<T> : Preference where T : class for the value types used in the implementation.
The following diagram shows an abbreviated inheritance structure of the Preference class and the implementations:
classDiagram
class Preference {
<<abstract>>
+string Name
+string Description
+GetValueAs~T~() T
}
class StructPreference~T~ {
<<abstract>>
+T Value
}
class ClassPreference~T~ {
<<abstract>>
+T Value
}
Preference <|-- StructPreference~T~
Preference <|-- ClassPreference~T~
StructPreference~T~ <|-- BooleanPreference : bool
StructPreference~T~ <|-- Int32Preference : int
ClassPreference~T~ <|-- EnumPreference : Enum
ClassPreference~T~ <|-- StringPreference : string
Supported Types
A Preference can have a Value of the following Type using the corresponding implementation:
| C# Keyword, if any | Type |
Preference Implementation |
|---|---|---|
bool |
System.Boolean |
BooleanPreference |
sbyte |
System.SBytes |
SBytePreference |
byte |
System.Byte |
BytePreference |
short |
System.Int16 |
Int16Preference |
ushrot |
System.UInt16 |
UInt16Preference |
int |
System.Int32 |
Int32Preference |
uint |
System.UInt32 |
UInt32Preference |
long |
System.Int64 |
Int64Preference |
ulong |
System.UInt64 |
UInt64Preference |
float |
System.Single |
SinglePreference |
double |
System.Double |
DoublePreference |
decimal |
System.Decimal |
DecimalPreference |
enum |
System.Enum |
EnumPreference[^1] |
string |
System.String |
StringPreference |
byte[] |
System.Byte[] |
BytesPreference |
| N/A | System.Net.IPAddress |
IPAddressPreference |
[^1]: The EnumPreference uses the System.Enum for the Value container to allow for runtime instantiation (see the PreferenceGroupBuilder.BuildFrom(object, bool, bool) method). Use the Preference.GetValueAs<T>() method and similar methods to retrieve the Value with the original enum. This is generally the best way for any Preference, but the others can be cast to their implementation and then access the Value directly. Also, when needing to build in code, it is best to use EnumPreferenceBuilder<T>, instead of EnumPreferenceBuilder, since the former provides better type checking at compile time. This is consistent with the uses in PreferenceGroupBuilder and PreferenceStoreBuilder, which use the EnumPreferenceBuilder<T>.
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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 (>= 13.0.4)
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 |
|---|---|---|
| 0.1.0 | 338 | 9/18/2025 |
| 0.0.13-alpha | 327 | 9/17/2025 |
| 0.0.12-alpha | 200 | 9/9/2025 |
| 0.0.11-alpha | 196 | 9/8/2025 |
| 0.0.10-alpha | 142 | 9/6/2025 |
| 0.0.9-alpha | 313 | 8/25/2025 |
| 0.0.8-alpha | 133 | 8/23/2025 |
| 0.0.7-alpha | 185 | 8/21/2025 |
| 0.0.6-alpha | 193 | 8/19/2025 |
| 0.0.5-alpha | 195 | 8/18/2025 |
| 0.0.4-alpha | 143 | 8/15/2025 |
| 0.0.3-alpha | 200 | 8/14/2025 |
| 0.0.2-alpha | 221 | 8/8/2025 |
| 0.0.1-alpha | 194 | 7/17/2025 |