ini-parser-new 2.6.2

dotnet add package ini-parser-new --version 2.6.2                
NuGet\Install-Package ini-parser-new -Version 2.6.2                
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="ini-parser-new" Version="2.6.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ini-parser-new --version 2.6.2                
#r "nuget: ini-parser-new, 2.6.2"                
#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 ini-parser-new as a Cake Addin
#addin nuget:?package=ini-parser-new&version=2.6.2

// Install ini-parser-new as a Cake Tool
#tool nuget:?package=ini-parser-new&version=2.6.2                

INI File Parser

A .NET, Mono and Unity3d compatible(*) library for reading/writing INI data from IO streams, file streams, and strings written in C#.

Also implements merging operations, both for complete ini files, sections, or even just a subset of the keys contained by the files.

(*) This library is 100% .NET code and does not have any dependencies on Windows API calls in order to be portable.

Install it with NuGet: https://www.nuget.org/packages/ini-parser-new/

Maintainer note

I will maintain the current fork of rickyah's ini-parser library.

Feel free to open issues and PR.

Actions:

  • publish version 2.6 with support for both net4.0 and netstandard2.0
  • integrate urgent PRs
  • review sources, tests, conventions, names; and publish v3.0
  • open repo to more contributors

Documentation: is in the upstream repo

Changelog

vNext

See WIP issues

v2.6

Support for net40 and netstandard2.0.

Version 2

Since the INI format isn't really a "standard", version 2 introduces a simpler way to customize INI parsing:

  • Pass a configuration object to an IniParser, specifying the behaviour of the parser. A default implementation is used if none is provided.
  • Derive from IniDataParser and override the fine-grained parsing methods.

Use

Installation

The library is published to NuGet and can be installed on the command-line from the directory containing your solution.

Getting Started

All code examples expect the following using clauses:

using IniParser;
using IniParser.Configuration;

INI data is stored in nested dictionaries, so accessing the value associated to a key in a section is straightforward. Load the data using one of the provided methods.

var parser = new FileIniDataParser();
IniData data = parser.ReadFile("Configuration.ini");

Retrieve the value for a key inside of a named section. Values are always retrieved as strings.

string useFullScreenStr = data["UI"]["fullscreen"];
// useFullScreenStr contains "true"
bool useFullScreen = bool.Parse(useFullScreenStr);

Modify the value in the dictionary, not the value retrieved, and save to a new file or overwrite.

data["UI"]["fullscreen"] = "true";
parser.WriteFile("Configuration.ini", data);

Head to the wiki for more usage examples, or check out the code of the example project

Merging ini files

Merging ini files is a one-method operation:

var parser = new IniParser.Parser.IniDataParser();

IniData config = parser.Parse(File.ReadAllText("global_config.ini"));
IniData user_config = parser.Parse(File.ReadAllText("user_config.ini"));
config.Merge(user_config);

// config now contains that data from both ini files, and the values of
// the keys and sections are overwritten with the values of the keys and
// sections that also existed in the user config file

Keep in mind that you can merge individual sections if you like:

config["user_settings"].Merge(user_config["user_settings"]);

Comments

The library allows modifying the comments from an ini file. However note than writing the file back to disk, the comments will be rearranged so comments are written before the element they refer to.

To query, add or remove comments, access the property Comments available both in SectionData and KeyData models.

var listOfCommentsForSection = config.["user_settings"].Comments;
var listOfCommentsForKey = config["user_settings"].GetKeyData("resolution").Comments;

Unity3D

You can easily use this library in your Unity3D projects. Just drop either the code or the DLL inside your project's Assets folder and you're ready to go!

ini-parser is actually being used in ProjectPrefs a free add-on available in the Unity Assets Store that allows you to set custom preferences for your project. I'm not affiliated with this project: Kudos to Garrafote for making this add-on.

## Contributing

Do you have an idea to improve this library, or did you happen to run into a bug? Please share your idea or the bug you found in the issues page, or even better: feel free to fork and contribute to this project with a Pull Request.

Product 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 net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  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.
  • .NETFramework 4.0

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on ini-parser-new:

Repository Stars
gus33000/UUPMediaCreator
An utility to create Windows Media files (.ISO, .WIM, .VHD) from Unified Update Platform files
Helion-Engine/Helion
A modern fast paced Doom FPS engine
Version Downloads Last updated
2.6.2 10,210 2/22/2023
2.6.1 310 2/22/2023

Support for net40 and netstandard2.0. Version 2.6.0 was bad, avoid it.