Delizious.Ini
1.23.0
dotnet add package Delizious.Ini --version 1.23.0
NuGet\Install-Package Delizious.Ini -Version 1.23.0
<PackageReference Include="Delizious.Ini" Version="1.23.0" />
<PackageVersion Include="Delizious.Ini" Version="1.23.0" />
<PackageReference Include="Delizious.Ini" />
paket add Delizious.Ini --version 1.23.0
#r "nuget: Delizious.Ini, 1.23.0"
#:package Delizious.Ini@1.23.0
#addin nuget:?package=Delizious.Ini&version=1.23.0
#tool nuget:?package=Delizious.Ini&version=1.23.0
Delizious Ini
What?
Delizious Ini is an easy to use .NET Standard library entirely written in C# for reading and writing of INI data that comes with an intuitive API design applying Domain-driven design (DDD).
It provides extensive configurability and allows to specify failure behaviors (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 both instance and operation level.
New features in version 1.23.0
Features
Delizious Ini provides the following features:
- Enumeration of sections
- Enumeration of properties
- Reading of a property
- Writing of a property
- Deletion of a section
- Deletion of a property
- Reading the comment of a section
- Reading the comment of a property
- Writing the comment of a section
- Writing the comment of a property
- Cloning an INI document
- Merging
- Configurability
- Property enumeration mode (
FailorFallback) - Property read mode (
Fail,FallbackorCustomFallback) - Property write mode (
CreateorUpdate) - Section deletion mode (
FailorIgnore) - Property deletion mode (
FailorIgnore) - Comment read mode (
Fail,FallbackorCustomFallback) - Comment write mode (
FailorIgnore) - Case sensitivity that specifies how to treat section names and property keys (
CaseSensitiveorCaseInsensitive) - New line string (
Environment,UnixorWindows) - Invalid line behavior (
FailorIgnore) - Property's assignment separator (defaults to
=) - Property's assignment spacer (
NoneorSpace) - Duplicate section behavior (
FailorMerge) - Duplicate property behavior (
Fail,IgnoreorOverride) - Section's beginning and end delimiters (default to
[and]) - Regular expression pattern (regex) for section name
- Newline string (
Environment,WindowsorUnix) - Comment string that indicates the beginning of a comment line (defaults to
;)
- Property enumeration mode (
↑
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
Configure default behavior of an INI document
// This configuration represents the loose configuration which is also predefined:
//var looseConfiguration = IniDocumentConfiguration.Loose;
var looseConfiguration =
IniDocumentConfiguration.Default
.WithCaseSensitivity(CaseSensitivity.CaseInsensitive) // Treat section names and property keys as case-insensitive
.WithNewlineString(NewlineString.Environment) // Use newline string as given by current environment
.WithSectionBeginningDelimiter(SectionBeginningDelimiter.Default) // Use default section beginning delimiter which is opening square bracket '['
.WithSectionEndDelimiter(SectionEndDelimiter.Default) // Use default section end delimiter which is closing square bracket ']'
.WithSectionNameRegex(SectionNameRegex.Default) // Use default section name regex which is '[\p{L}\p{M}\p{N}\p{P}\p{S}\p{Zs}]+'
.WithDuplicatePropertyBehavior(DuplicatePropertyBehavior.Ignore) // Ignore subsequent occurrences of a duplicate property by using the first occurrence of such a property
.WithDuplicateSectionBehavior(DuplicateSectionBehavior.Merge) // Merge a duplicate section
.WithInvalidLineBehavior(InvalidLineBehavior.Ignore) // Ignore when a line is invalid and cannot be parsed on loading
.WithPropertyAssignmentSeparator(PropertyAssignmentSeparator.Default) // Use default property assignment separator which is equality sign '='
.WithPropertyAssignmentSpacer(PropertyAssignmentSpacer.None) // Use no property assignment spacer
.WithPropertyEnumerationMode(PropertyEnumerationMode.Fallback) // Fallback to empty collection of property keys when section does not exist
.WithPropertyReadMode(PropertyReadMode.Fallback) // Fallback to empty string when property to read does not exist
.WithPropertyWriteMode(PropertyWriteMode.Create) // Create a new property or update an existing property
.WithPropertyDeletionMode(PropertyDeletionMode.Ignore) // Ignore when property to delete does not exist
.WithSectionDeletionMode(SectionDeletionMode.Ignore) // Ignore when section to delete does not exist
.WithCommentString(CommentString.Default) // Use default comment string that indicates the beginning of a comment line which is a semicolon ';'
.WithCommentReadMode(CommentReadMode.Fallback) // Fallback to none comment when section or property to read comment does not exist
.WithCommentWriteMode(CommentWriteMode.Ignore); // Ignore when section or property to write the comment does not exist
// This configuration represents the strict configuration which is also predefined:
//var strictConfiguration = IniDocumentConfiguration.Strict;
var strictConfiguration =
IniDocumentConfiguration.Default
.WithCaseSensitivity(CaseSensitivity.CaseInsensitive) // Treat section names and property keys as case-insensitive
.WithNewlineString(NewlineString.Environment) // Use newline string as given by current environment
.WithSectionBeginningDelimiter(SectionBeginningDelimiter.Default) // Use default section beginning delimiter which is opening square bracket '['
.WithSectionEndDelimiter(SectionEndDelimiter.Default) // Use default section end delimiter which is closing square bracket ']'
.WithSectionNameRegex(SectionNameRegex.Default) // Use default section name regex which is '[\p{L}\p{M}\p{N}\p{P}\p{S}\p{Zs}]+'
.WithDuplicatePropertyBehavior(DuplicatePropertyBehavior.Fail) // Throw exception when a duplicate property occurs
.WithDuplicateSectionBehavior(DuplicateSectionBehavior.Fail) // Throw exception when a duplicate section occurs
.WithInvalidLineBehavior(InvalidLineBehavior.Fail) // Throw exception when a line is invalid and cannot be parsed on loading
.WithPropertyAssignmentSeparator(PropertyAssignmentSeparator.Default) // Use default property assignment separator which is equality sign '='
.WithPropertyAssignmentSpacer(PropertyAssignmentSpacer.None) // Use no property assignment spacer
.WithPropertyEnumerationMode(PropertyEnumerationMode.Fail) // Throw exception when section to enumerate properties does not exist
.WithPropertyReadMode(PropertyReadMode.Fail) // Throw exception when property to read to does not exist
.WithPropertyWriteMode(PropertyWriteMode.Update) // Update existing property only but throw exception when property to write does not exist
.WithPropertyDeletionMode(PropertyDeletionMode.Fail) // Throw exception when property to delete does not exist
.WithSectionDeletionMode(SectionDeletionMode.Fail) // Throw exception when section to delete does not exist
.WithCommentString(CommentString.Default) // Use default comment string that indicates the beginning of a comment line which is a semicolon ';'
.WithCommentReadMode(CommentReadMode.Fail) // Throw exception when section or property to read comment does not exist
.WithCommentWriteMode(CommentWriteMode.Fail); // Throw exception when section or property to write the comment does not exist
↑
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);
↑
Enumeration of 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);
}
↑
Enumeration of 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);
}
The enumeration of properties supports the following modes:
| Mode | Description |
|---|---|
PropertyEnumerationMode.Fail |
Throw a SectionNotFoundException when the section does not exist. |
PropertyEnumerationMode.Fallback |
Fall back to an empty collection of properties when the section does not exist. |
↑
Reading of a property
The reading of a property supports the following modes:
| Mode | Description |
|---|---|
PropertyReadMode.Fail |
Throw a SectionNotFoundException when the section does not exist, or throw a PropertyNotFoundException when the section exists but the property does not exist. |
PropertyReadMode.Fallback |
Fall back to PropertyValue.None if the section or property does not exist. |
PropertyReadMode.CustomFallback |
Fall back to the given custom property value if the section or property does not exist. |
↑
Writing of a property
The writing of a property supports the following modes:
| Mode | Description |
|---|---|
PropertyWriteMode.Create |
Create a new property. If the property already exists, it will be overwritten. If the section does not exist, a new section is created. If the section exists but the property itself does not exist, a new property is created. |
PropertyWriteMode.Update |
Update an existing property and require that both the section and property exist. Throw a SectionNotFoundException when the section does not exist, or throw a PropertyNotFoundException when the section exists but the property does not exist. |
↑
Deletion of a 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);
The deletion of a section supports the following modes:
| Mode | Description |
|---|---|
SectionDeletionMode.Fail |
Throw a SectionNotFoundException when the section does not exist. |
SectionDeletionMode.Ignore |
Silently ignore if the section does not exist. |
↑
Deletion of a 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);
The deletion of a property supports the following modes:
| Mode | Description |
|---|---|
PropertyDeletionMode.Fail |
Throw a SectionNotFoundException when the section does not exist, or throw a PropertyNotFoundException when the section exists but the property does not exist. |
PropertyDeletionMode.Ignore |
Silently ignore if the section or the property does not exist. |
↑
Reading the comment of a section
const string ini = """
;This is a sample
;multiline
;comment. :)
[Section]
Property=Value
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
var comment = iniDocument.ReadComment("Section");
Console.WriteLine(comment);
Reading the comment of a section supports the following modes:
| Mode | Description |
|---|---|
CommentReadMode.Fail |
Throw a SectionNotFoundException when the section does not exist. |
CommentReadMode.Fallback |
Fall back to none comment if the section does not exist. |
CommentReadMode.CustomFallback |
Fall back to a custom fallback comment if the section does not exist. |
↑
Reading the comment of a property
const string ini = """
[Section]
;This is a sample
;multiline
;comment. :)
Property=Value
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
var comment = iniDocument.ReadComment("Section", "Property");
Console.WriteLine(comment);
Reading the comment of a property supports the following modes:
| Mode | Description |
|---|---|
CommentReadMode.Fail |
Throw a SectionNotFoundException when the section does not exist, or throw a PropertyNotFoundException when the section exists but the property does not exist. |
CommentReadMode.Fallback |
Fall back to none comment if the section or property does not exist. |
CommentReadMode.CustomFallback |
Fall back to a custom fallback comment if the section or property does not exist. |
↑
Writing the comment of a section
const string ini = """
[Section]
Property=Value
""";
const string comment = """
This is a sample
multiline
comment. :)
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
iniDocument.WriteComment("Section", comment);
using var textWriter = new StringWriter();
iniDocument.SaveTo(textWriter);
textWriter.Flush();
Console.WriteLine(textWriter);
Writing the comment of a section supports the following modes:
| Mode | Description |
|---|---|
CommentWriteMode.Fail |
Throw a SectionNotFoundException when the section does not exist. |
CommentWriteMode.Ignore |
Silently ignore if the section does not exist. |
↑
Writing the comment of a property
const string ini = """
[Section]
Property=Value
""";
const string comment = """
This is a sample
multiline
comment. :)
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
iniDocument.WriteComment("Section", "Property", comment);
using var textWriter = new StringWriter();
iniDocument.SaveTo(textWriter);
textWriter.Flush();
Console.WriteLine(textWriter);
Writing the comment of a property supports the following modes:
| Mode | Description |
|---|---|
CommentWriteMode.Fail |
Throw a SectionNotFoundException when the section does not exist, or throw a PropertyNotFoundException when the section exists but the property does not exist. |
CommentWriteMode.Ignore |
Silently ignore if the section or the property does not exist. |
↑
Merging
const string ini = """
[SourceOnlySection]
Property=I reside here.
[Section]
SourceOnlyProperty=I'm kept.
; I'm a property comment and will be preserved.
Property=I will be update.
; I'm a section comment and will be preserved.
[SectionWithComment]
; I'm a property comment from source and will be updated.
PropertyWithComment=Sample
""";
const string other = """
[Section]
Property=I'm merged.
[NewSection]
NewProperty=I'm a new property from other and merged.
[SectionWithComment]
; I'm a property comment from other and merged.
PropertyWithComment=Sample
""";
using var textReader = new StringReader(ini);
var iniDocument = IniDocument.LoadFrom(textReader, IniDocumentConfiguration.Default);
using var otherReader = new StringReader(other);
var otherDocument = IniDocument.LoadFrom(otherReader, IniDocumentConfiguration.Default);
iniDocument.Merge(otherDocument);
using var textWriter = new StringWriter();
iniDocument.SaveTo(textWriter);
textWriter.Flush();
Console.WriteLine(textWriter);
↑
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. 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
- ini-parser-netstandard (>= 2.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Delizious.Ini:
| Repository | Stars |
|---|---|
|
bernatvadell/muonline
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.23.0 | 90 | 5/25/2026 |
| 1.22.0 | 147 | 3/29/2026 |
| 1.21.0 | 114 | 3/29/2026 |
| 1.20.0 | 3,221 | 7/16/2025 |
| 1.19.0 | 593 | 6/2/2025 |
| 1.18.0 | 231 | 5/4/2025 |
| 1.17.0 | 2,086 | 4/14/2025 |
| 1.16.0 | 205 | 4/6/2025 |
| 1.15.0 | 221 | 3/30/2025 |
| 1.14.0 | 157 | 3/15/2025 |
| 1.13.0 | 269 | 3/9/2025 |
| 1.12.0 | 293 | 3/6/2025 |
| 1.11.0 | 532 | 2/22/2025 |
| 1.10.0 | 189 | 2/17/2025 |
| 1.9.0 | 183 | 2/5/2025 |
| 1.8.0 | 152 | 1/23/2025 |
| 1.7.0 | 179 | 1/19/2025 |
| 1.6.0 | 183 | 1/11/2025 |
| 1.5.0 | 197 | 1/4/2025 |
| 1.4.0 | 214 | 1/1/2025 |