AbYzzX.Extensions.Settings
0.0.7.1
dotnet add package AbYzzX.Extensions.Settings --version 0.0.7.1
NuGet\Install-Package AbYzzX.Extensions.Settings -Version 0.0.7.1
<PackageReference Include="AbYzzX.Extensions.Settings" Version="0.0.7.1" />
<PackageVersion Include="AbYzzX.Extensions.Settings" Version="0.0.7.1" />
<PackageReference Include="AbYzzX.Extensions.Settings" />
paket add AbYzzX.Extensions.Settings --version 0.0.7.1
#r "nuget: AbYzzX.Extensions.Settings, 0.0.7.1"
#:package AbYzzX.Extensions.Settings@0.0.7.1
#addin nuget:?package=AbYzzX.Extensions.Settings&version=0.0.7.1
#tool nuget:?package=AbYzzX.Extensions.Settings&version=0.0.7.1
Abyzz.Extensions.Settings
A flexible and extensible settings management library for .NET applications, providing a provider-based architecture for managing configuration data from multiple sources.
Overview
Abyzz.Extensions.Settings is a lightweight library that offers a unified interface for reading and writing configuration settings. It follows a provider pattern, allowing you to implement custom providers for different configuration sources (INI files, JSON, XML, databases, etc.).
Features
- Provider-based architecture for flexible configuration sources
- Section-based settings organization
- Case-insensitive key lookups
- Type-safe value retrieval with default values
- Support for multiple data types (string, int, long, bool, double, decimal, DateTime, enum)
- Built-in INI file provider (via separate package)
- Simple and intuitive API
Installation
Install the core package:
dotnet add package AbYzzX.Extensions.Settings
For INI file support, also install:
dotnet add package AbYzzX.Extensions.Settings.Ini
Getting Started
Basic Usage
using AbYzzX.Extensions.Settings;
// Create a settings builder
var builder = new SettingsBuilder();
// Add providers (e.g., INI file provider)
builder.AddProvider(new IniSettingsProvider("config.ini"));
// Build and load settings
var settings = builder.Build();
// Read settings
var value = settings.GetSetting("Database", "ConnectionString");
Using Extension Methods for Type-Safe Access
// Get strongly-typed values with defaults
var port = settings.GetInt32("Server", "Port", 8080);
var isEnabled = settings.GetBool("Features", "EnableLogging", false);
var timeout = settings.GetDouble("Connection", "Timeout", 30.0);
Working with Sections
// Get a specific section
var dbSection = settings.GetSection("Database");
if (dbSection != null)
{
var host = dbSection.GetString("Host", "localhost");
var port = dbSection.GetInt32("Port", 5432);
}
// Add a new section
var section = settings.AddSection("NewSection");
section.SetValue("Key", "Value");
// Check if section exists
if (settings.ContainsSection("Database"))
{
// Section exists
}
// Get all section names
var sectionNames = settings.GetSectionNames();
Modifying and Saving Settings
// Add or modify values
var section = settings.GetSection("Database") ?? settings.AddSection("Database");
section.SetValue("ConnectionString", "Server=localhost;Database=mydb");
// Save changes to all providers
settings.Save();
Architecture
Core Interfaces
- ISettings: Main interface for settings management
- ISettingsSection: Represents a section containing key-value pairs
- ISettingsProvider: Interface for implementing custom configuration providers
Extension Methods
The library provides extension methods for both ISettings and ISettingsSection to retrieve typed values:
GetString()GetInt16(),GetInt32(),GetInt64()GetBool()GetDouble(),GetDecimal()GetDateTime()GetEnum<T>()
All methods support optional default values.
Boolean Values
By default, the following values are considered as true (case-insensitive):
- "true"
- "1"
- "yes"
You can customize this by modifying:
SettingsExtensions.BoolTrueValues = new[] { "true", "1", "yes", "on" };
INI File Provider
The INI provider supports standard INI file format:
[Database]
Host = localhost
Port = 5432
ConnectionString = Server=localhost;Database=mydb
[Features]
EnableLogging = true
MaxRetries = 3
Using the INI Provider
var builder = new SettingsBuilder();
// Required file (throws exception if not found)
builder.AddProvider(new IniSettingsProvider("config.ini"));
// Optional file (no error if missing)
builder.AddProvider(new IniSettingsProvider("optional.ini", isRequired: false));
var settings = builder.Build();
Comments in INI files start with # and are ignored during parsing.
Creating Custom Providers
Implement the ISettingsProvider interface:
public class CustomProvider : ISettingsProvider
{
public void Load(ISettings settings)
{
// Load configuration from your source
var section = settings.AddSection("MySection");
section.SetValue("Key", "Value");
}
public void Save(ISettings settings)
{
// Save configuration to your source
foreach (var sectionName in settings.GetSectionNames())
{
var section = settings.GetSection(sectionName);
// Write section data to your storage
}
}
}
Requirements
- .NET 10.0 or later
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- AbYzzX.Extensions.Settings.Abstractions (>= 0.0.7.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AbYzzX.Extensions.Settings:
| Package | Downloads |
|---|---|
|
AbYzzX.Extensions.Settings.Ini
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.