LCSilverio.IniMapper
1.0.0
dotnet add package LCSilverio.IniMapper --version 1.0.0
NuGet\Install-Package LCSilverio.IniMapper -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="LCSilverio.IniMapper" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LCSilverio.IniMapper" Version="1.0.0" />
<PackageReference Include="LCSilverio.IniMapper" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LCSilverio.IniMapper --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LCSilverio.IniMapper, 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.
#:package LCSilverio.IniMapper@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LCSilverio.IniMapper&version=1.0.0
#tool nuget:?package=LCSilverio.IniMapper&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
IniMapper — Simple INI Serializer & Deserializer for C#
Overview
- I've created
IniMapperto be essentially a lightweight C# package that provides easy serialization and deserialization of INI files into strongly typed objects — similar to howSystem.Text.Jsonworks for JSON. - I just wanted that "easy" abstraction on other legacy projects where i need to work with INI files but don't wanted the hassle of creating a factory method or something like that hidden in that good old "Utilities" folder we all have
It supports:
- Deserializing from strings, byte arrays, or file paths
- Serializing any object back into a INI formatted text block
- Mapping sections to properties and keys to fields
- Case-insensitive property matching
Summary
| Method | Description |
|---|---|
Deserialize<T>(string content) |
Deserializes an INI-formatted string into a typed object |
Deserialize<T>(byte[] bytes) |
Deserializes an INI document from a UTF-8 byte array |
DeserializeFromFile<T>(string filePath) |
Deserializes from a file path |
Serialize(object obj) |
Serializes a C# object to INI format |
Table of Contents
- Overview
- Summary
- Table of Contents
- Installation
- Example Data Model
- Deserialization
- Serialization
- Notes
- Example Output Structure
- License
Installation
Simply add the IniMapper.cs file to your project — no external dependencies required.
Example Data Model
public class Config
{
public DatabaseSection Database { get; set; } = new();
public AppSection App { get; set; } = new();
}
public class DatabaseSection
{
public string Server { get; set; }
public int Port { get; set; }
}
public class AppSection
{
public string Name { get; set; }
public string Version { get; set; }
}
Deserialization
From string
var iniText = @"
[Database]
Server = localhost
Port = 5432
[App]
Name = MyApp
Version = 1.0.0
";
var config = IniMapper.Deserialize<Config>(iniText);
Console.WriteLine(config.Database.Server); // localhost
From file
var config = IniMapper.DeserializeFromFile<Config>("settings.ini");
Console.WriteLine(config.App.Version); // e.g. "1.0.0"
From byte array
byte[] iniBytes = File.ReadAllBytes("settings.ini");
var config = IniMapper.Deserialize<Config>(iniBytes);
Serialization
var cfg = new Config
{
Database = new DatabaseSection { Server = "localhost", Port = 3306 },
App = new AppSection { Name = "DemoApp", Version = "2.5" }
};
string iniOutput = IniMapper.Serialize(cfg);
File.WriteAllText("output.ini", iniOutput);
Output:
[Database]
Server=localhost
Port=3306
[App]
Name=DemoApp
Version=2.5
Notes
- Properties are matched case-insensitively.
- Only public instance properties are mapped.
- Comment lines starting with
;or#are ignored. - Null values are skipped during serialization.
- Each class property in the root type becomes an INI section.
Example Output Structure
INI File:
[Database]
Server=localhost
Port=5432
[App]
Name=ExampleApp
Version=1.0
C# Object Access:
var cfg = IniMapper.Deserialize<Config>(iniText);
Console.WriteLine(cfg.Database.Server); // localhost
Console.WriteLine(cfg.App.Name); // ExampleApp
License
This utility is released under the MIT License.
Feel free to modify and use it in both personal and commercial projects.
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.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 | 205 | 10/21/2025 |