![]() |
VOOZH | about |
dotnet add package SoftCircuits.IniFileParser --version 3.0.0
NuGet\Install-Package SoftCircuits.IniFileParser -Version 3.0.0
<PackageReference Include="SoftCircuits.IniFileParser" Version="3.0.0" />
<PackageVersion Include="SoftCircuits.IniFileParser" Version="3.0.0" />Directory.Packages.props
<PackageReference Include="SoftCircuits.IniFileParser" />Project file
paket add SoftCircuits.IniFileParser --version 3.0.0
#r "nuget: SoftCircuits.IniFileParser, 3.0.0"
#:package SoftCircuits.IniFileParser@3.0.0
#addin nuget:?package=SoftCircuits.IniFileParser&version=3.0.0Install as a Cake Addin
#tool nuget:?package=SoftCircuits.IniFileParser&version=3.0.0Install as a Cake Tool
👁 NuGet version (SoftCircuits.IniFileParser)
Install-Package SoftCircuits.IniFileParser
IniFile is a lightweight .NET class library that makes it easy to read and write INI files. It provide direct support for reading and writing string, int, double and bool settings. It can return all of the sections in an INI file, and also return all the settings within a particular INI-file section.
To write an INI file, create an instance of the IniFile class and call the SetSetting() method to set each setting. This method is overloaded to accept string, int, double and bool value types. Then call the Save() method to write the settings to a file.
// Write values
IniFile file = new IniFile();
file.SetSetting(IniFile.DefaultSectionName, "Name", "Bob Smith");
file.SetSetting(IniFile.DefaultSectionName, "Age", 34);
file.SetSetting(IniFile.DefaultSectionName, "Rating", 123.45);
file.SetSetting(IniFile.DefaultSectionName, "Active", true);
file.Save(path);
To read an INI file, create an instance of the IniFile class and call the Load() method to read the settings from a file. Then call the GetSetting() method to get each setting.
The GetSetting() method accepts a default value parameter. The method returns the value of this parameter if the setting was not found or could not be converted to the specified type. The GetSetting() method is overloaded to accept default values of type string, int, double and bool. The default value parameter determines the return type.
// Read values
IniFile file = new IniFile();
file.Load(path);
string name = file.GetSetting(IniFile.DefaultSectionName, "Name", string.Empty);
int age = file.GetSetting(IniFile.DefaultSectionName, "Age", 0);
double rating = file.GetSetting(IniFile.DefaultSectionName, "Rating", 0.0);
bool active = file.GetSetting(IniFile.DefaultSectionName, "Active", false);
If any settings are found that are not under a section header, they will be added to the IniFile.DefaultSectionName section.
Use the GetSections() method to retrieve all the sections in the file.
IEnumerable<string> sections = file.GetSections();
Use the GetSectionSettings() method to retrieve all the settings in a section.
IEnumerable<IniSetting> settings = file.GetSectionSettings(sectionName);
IniFile provides support for file comments. Comments can provide notes that are otherwise ignored by the parser. By default, any line with a semicolon (;) as the first non-space character is assumed to be a comment. The comment character can be changed by setting the CommentCharacter property.
Any comments found when reading an INI file are stored in the Comments collection. And any comments in this collection will be written when saving an INI file. This makes it easy to add comments to INI files you create, or to maintain comments in INI files you modify. (Note, however, that all comments are written to the start of the INI file regardless of where those comments might have been when read.)
Empty lines are ignored.
By default, the bool version of the GetSetting() method understands the words "true", "false", "yes", "no", "on", "off", "1" and "0", and will convert those words to the corresponding bool value. The comparison is not case-sensitive. In addition, any string value that can be interpreted as an integer value will considered true if that integer value is non-zero, or false if that integer value is zero.
However, you can override these settings by passing an instance of the BoolOptions class to the IniFile constructor. The following example creates an instance of the BoolOptions class, sets the string comparer to use when comparing Boolean words, replaces the default Boolean words with a new list, specifies that strings that can be interpreted as integers should be translated to bool values, and passes the object to the IniFile constructor.
BoolOptions options = new BoolOptions(StringComparer.CurrentCultureIgnoreCase);
options.SetBoolWords(new[] {
new BoolWord("sure", true),
new BoolWord("okay", true),
new BoolWord("yeppers", true),
new BoolWord("nope", false),
new BoolWord("nah", false),
new BoolWord("nopers", false),
});
options.NonZeroNumbersAreTrue = true;
IniFile file = new IniFile(StringComparer.CurrentCultureIgnoreCase, options);
NOTE: The SetBoolWords() method will search the word list to find the first word with a true value and the first word with a false value, and these words will then be used by the SetSetting() method to write bool values. In the example above, any bool values would be written as "sure" or "nope". Keep this in mind if you are writing INI files that may be read by other programs, as INI parsers expecting bool values to be "true" or "false" would be unable to correctly interpret such a file. If the list of words passed to SetBoolWords() does not include any words with a true value, or does not include any words with a false value, an exception is thrown.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on SoftCircuits.IniFileParser:
| Package | Downloads |
|---|---|
|
revealnext.CommonLibs.Common
Part of REGEN Platform 13 |
|
|
G1.Common
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 495 | 3/11/2026 |
| 2.7.0 | 118,827 | 1/20/2025 |
| 2.6.0 | 6,685 | 12/22/2024 |
| 2.5.0 | 13,076 | 3/24/2024 |
| 2.1.0 | 16,542 | 12/12/2021 |
| 2.0.1 | 3,195 | 4/30/2021 |
| 2.0.0 | 654 | 2/21/2021 |
| 1.0.11 | 1,382 | 5/15/2020 |
| 1.0.10 | 753 | 3/12/2020 |
| 1.0.9 | 765 | 3/1/2020 |
| 1.0.8 | 823 | 2/15/2020 |
| 1.0.7 | 773 | 2/11/2020 |
| 1.0.6 | 946 | 7/22/2019 |
| 1.0.5 | 757 | 7/18/2019 |
| 1.0.4 | 785 | 7/15/2019 |
| 1.0.3 | 744 | 7/14/2019 |
| 1.0.2 | 750 | 7/14/2019 |
| 1.0.1 | 746 | 7/7/2019 |
| 1.0.0 | 809 | 7/7/2019 |
Optimized INI file line parsing; Added support for .NET 10; Minor fixes and tweaks.