IniCore 1.0.0

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

// Install IniCore as a Cake Tool
#tool nuget:?package=IniCore&version=1.0.0                

IniCore LICENSE Build

A .NET library for parsing and generating INI configuration files with support for nested sections and JSON conversion.

Features

  • Parse and generate INI-formatted content
  • Support nested sections using dot notation (e.g., [parent.child])
  • Handle relative section nesting (e.g., [.child] for relative hierarchy)
  • Convert between INI structure and JSON objects
  • Preserve entry order and section hierarchy
  • Handle entries before any section declarations
TargetFramework(s) Package
IniCore netstandard2.0 net6.0 net7.0 net8.0 net9.0 alternate text is missing from this package README image

Installation

dotnet add package IniCore

Usage

Parsing INI Content

string iniContent = @"
[server.database]
host = localhost
port = 1433";

IniConfig config = IniParser.Parse(iniContent);

// Get database host value
string host = config.Sections
    .First(s => s.Name == "server")
    .SubSections.First(s => s.Name == "database")
    .Entries.First(e => e.Key == "host").Value;

Creating Configurations Programmatically

var config = new IniConfig
{
    Entries =
    [
        new IniEntry("debug", "true"),
    ],
    Sections =
    [
        new IniSection("server")
        {
            SubSections =
            [
                new IniSection("database")
                {
                    Entries =
                    [
                        new IniEntry("host", "localhost"),
                        new IniEntry("port", "1433")
                    ],
                },
            ],
        },
    ],
};

// Generate INI configuration string
string outputConfig = config.ToString();
Console.WriteLine(outputConfig);

Deserialize UCI Configuration to custom config type using json

username = admin

[server]
timeout = 30

[server.database]
host = localhost
port = 1433

[.cache]
enabled = true
// custom config type
public class CustomConfig
{
    [JsonPropertyName("username")]
    public string? UserName { get; set; }

    [JsonPropertyName("server")]
    public Server? Server { get; set; }
}

public class Server
{
    [JsonPropertyName("timeout")]
    public int Timeout { get; set; }

    [JsonPropertyName("database")]
    public ServerDatabase? Database { get; set; }
}

public class ServerDatabase
{
    [JsonPropertyName("host")]
    public string? Host { get; set; }
    [JsonPropertyName("port")]
    public int Port { get; set; }

    [JsonPropertyName("cache")]
    public ServerDatabaseCache? Cache { get; set; }
}

public class ServerDatabaseCache
{
    [JsonConverter(typeof(BooleanJsonConverter))] // use custom json converter
    [JsonPropertyName("enabled")]
    public bool Enabled { get; set; }
}

IniConfig config = IniParser.Parse(iniContent);
// convert UciConfig to JsonObject that is able to deserialize to custom type.
JsonObject jsonObject = config.ToSerializableJsonObject();
JsonSerializerOptions serializerOptions = new() { NumberHandling = JsonNumberHandling.AllowReadingFromString };
CustomConfig? customConfig = jsonObject.Deserialize<CustomConfig>(serializerOptions);

TODO

  • Add support for reading and writing comments
  • Implement escaped quote handling in string values
  • Enhance error handling for malformed sections
  • Add support for comment preservation during serialization

Notes

  • Nested Sections: Use dot notation for hierarchical sections (e.g., [parent.child])
  • Relative Nesting: Start section name with dot to nest under previous section
  • Current Limitations: Comments are currently ignored during parsing/serialization

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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 is compatible.  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. 
.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

  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

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.0.0 100 2/28/2025