Delizious.Ini
1.1.0
dotnet add package Delizious.Ini --version 1.1.0
NuGet\Install-Package Delizious.Ini -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="Delizious.Ini" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Delizious.Ini --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Delizious.Ini, 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 Delizious.Ini as a Cake Addin #addin nuget:?package=Delizious.Ini&version=1.1.0 // Install Delizious.Ini as a Cake Tool #tool nuget:?package=Delizious.Ini&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Delizious Ini
What?
Delizious Ini is an easy to use .NET Standard library entirely written in C# for reading and writing of INI data.
Features
Delizious Ini provides the following features:
- Intuitive API design applying Domain-driven design (DDD)
- Enumeration of sections
- Enumeration of properties contained in a section
- Reading and writing of a property
- Deletion of sections or properties
- Configurability of the failure behavior (e.g. throw a specific exception in case a section or property does not exist, or proceed with a fallback behavior) for almost every operation on instance and operation level
- Configurability of case sensitivity that specifies how to treat section names and property keys
Upcoming features:
- Configurability of behavior in case of invalid lines
- Configurability of behavior whether to allow duplicated sections
- Configurability of behavior whether to allow duplicated keys
- Configurability of the property's assignment character and its spacer
- Configurability of the new line string
- Support for comments
- Merge two INI documents
- ...
Getting started
To install Delizious Ini, run the following command in the respective console:
Package Manager Console
PM> Install-Package Delizious.Ini
.NET CLI Console
> dotnet add package Delizious.Ini
Quick start
const string ini = """
[Section]
Property=Current value
AnotherProperty=Another value
[EmptySection]
""";
using var textReader = new StringReader(ini);
// Use default configuration
var configuration = IniDocumentConfiguration.Default
.WithCaseSensitivity(CaseSensitivity.CaseSensitive); // Treat section names and property keys as case-sensitive (by default, case-insensitive)
var iniDocument = IniDocument.LoadFrom(textReader, configuration);
// Read existing property
var originalValue = iniDocument.ReadProperty("Section", "Property");
Console.WriteLine($@"Original property value: {originalValue}");
// Update existing property
iniDocument.WriteProperty("Section", "Property", "This is the new value");
var updatedValue = iniDocument.ReadProperty("Section", "Property");
Console.WriteLine($@"Updated property value: {updatedValue}");
// Write new property
iniDocument.WriteProperty("NewSection", "NewProperty", "NewValue");
// Delete section
iniDocument.DeleteSection("EmptySection");
// Delete property
iniDocument.DeleteProperty("Section", "AnotherProperty");
Console.WriteLine();
Console.WriteLine(@"INI document:");
iniDocument.SaveTo(Console.Out);
Examples
Load and save
const string ini = """
[Section]
Property=Current value
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
// Save entire INI document to text writer by using Console.Out to output content
var textWriter = Console.Out;
iniDocument.SaveTo(textWriter);
Enumerate sections
const string ini = """
[Section]
Property=Current value
[EmptySection]
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
foreach (var sectionName in iniDocument.EnumerateSections())
{
Console.WriteLine(sectionName);
}
Enumerate properties
const string ini = """
[Section]
Property=Current value
AnotherProperty=Another value
EmptyProperty=
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
foreach (var propertyName in iniDocument.EnumerateProperties("Section"))
{
Console.WriteLine(propertyName);
}
Delete section
const string ini = """
[Section]
Property=Current value
[EmptySection]
[AnotherSection]
AnotherProperty=With another value
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
iniDocument.DeleteSection("EmptySection");
iniDocument.SaveTo(Console.Out);
Delete property
const string ini = """
[Section]
Property=Current value
AnotherProperty=Another value
EmptyProperty=
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
iniDocument.DeleteProperty("Section", "Property");
iniDocument.SaveTo(Console.Out);
License
MIT License
https://opensource.org/license/mit
Socialize
If you like or use my work and you are interested in this kind of software development let's get in touch. 😃
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. |
.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.
-
.NETStandard 2.0
- ini-parser-netstandard (>= 2.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.