Delizious.Ini
1.20.0
dotnet add package Delizious.Ini --version 1.20.0
NuGet\Install-Package Delizious.Ini -Version 1.20.0
<PackageReference Include="Delizious.Ini" Version="1.20.0" />
<PackageVersion Include="Delizious.Ini" Version="1.20.0" />
<PackageReference Include="Delizious.Ini" />
paket add Delizious.Ini --version 1.20.0
#r "nuget: Delizious.Ini, 1.20.0"
#:package Delizious.Ini@1.20.0
#addin nuget:?package=Delizious.Ini&version=1.20.0
#tool nuget:?package=Delizious.Ini&version=1.20.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.
New features in version 1.20.0
- Document available modes
PropertyEnumerationMode
,PropertyReadMode
,PropertyWriteMode
,SectionDeletionMode
,PropertyDeletionMode
,CommentReadMode
andCommentWriteMode
in README - Improve readability of Features section in README
Features
Delizious Ini provides the following features:
- Intuitive API design applying Domain-driven design (DDD)
- 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
- Configurability
- 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
- Case sensitivity that specifies how to treat section names and property keys
- Invalid line behavior (
Fail
orIgnore
) - Property's assignment separator and assignment spacer
- Duplicate section behavior (
Fail
orMerge
) - Duplicate property behavior (
Fail
,Ignore
orOverride
) - Section's beginning and end delimiters
- Regular expression pattern (regex) for section name
- Newline string (
Environment
,Windows
orUnix
) - Comment string that indicates the beginning of a comment line
Upcoming features:
- 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
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. |
↑
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
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated | |
---|---|---|---|
1.20.0 | 132 | 7/16/2025 | |
1.19.0 | 341 | 6/2/2025 | |
1.18.0 | 167 | 5/4/2025 | |
1.17.0 | 747 | 4/14/2025 | |
1.16.0 | 132 | 4/6/2025 | |
1.15.0 | 152 | 3/30/2025 | |
1.14.0 | 89 | 3/15/2025 | |
1.13.0 | 198 | 3/9/2025 | |
1.12.0 | 219 | 3/6/2025 | |
1.11.0 | 467 | 2/22/2025 | |
1.10.0 | 123 | 2/17/2025 | |
1.9.0 | 112 | 2/5/2025 | |
1.8.0 | 104 | 1/23/2025 | |
1.7.0 | 111 | 1/19/2025 | |
1.6.0 | 109 | 1/11/2025 | |
1.5.0 | 133 | 1/4/2025 | |
1.4.0 | 147 | 1/1/2025 | |
1.3.0 | 114 | 12/29/2024 | |
1.2.0 | 129 | 12/27/2024 | |
1.1.0 | 112 | 12/23/2024 | |
1.0.0 | 109 | 12/22/2024 | |
0.27.2 | 265 | 12/15/2024 | |
0.27.1 | 254 | 12/15/2024 | |
0.27.0 | 252 | 12/14/2024 | |
0.26.0 | 342 | 10/24/2024 |