https://github.com/kris701/initoolssharp
Some simple tools to work with INI files
https://github.com/kris701/initoolssharp
ini parser
Last synced: over 1 year ago
JSON representation
Some simple tools to work with INI files
- Host: GitHub
- URL: https://github.com/kris701/initoolssharp
- Owner: kris701
- License: mit
- Created: 2024-03-27T17:40:23.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-28T07:10:23.000Z (about 2 years ago)
- Last Synced: 2025-01-21T06:26:07.017Z (over 1 year ago)
- Topics: ini, parser
- Language: C#
- Homepage:
- Size: 47.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://github.com/kris701/IniToolsSharp/actions/workflows/dotnet-desktop.yml)







INI Tools Sharp is a little project to manipulate and output INI files.
You can find it on the [NuGet Package Manager](https://www.nuget.org/packages/IniToolsSharp/) or the [GitHub Package Manager](https://github.com/kris701/IniToolsSharp/pkgs/nuget/IniToolsSharp).
# How to Use
The package is inspired by that of [System.Text.Json](https://www.nuget.org/packages/System.Text.Json/9.0.0-preview.2.24128.5), where you can access two primary static methods, `INISerialiser.Deserialise` and `INISerialiser.Serialise` to convert generic classes into INI format and back.
A class represents a section by giving it a `IniSectionAttribute` and a name.
## Example
Test class to work with:
```csharp
public class Section1
{
public bool Value1 { get; set; } = false;
public int Value2 { get; set; } = -1;
}
public class SomeSettings
{
[IniSection("SectionName")]
public Section1 Section { get; set; } = new Section1();
}
```
You can then serialise it into a INI file format:
```csharp
var text = IniSerialiser.Serialise(new SomeSettings());
```
This will output text as follows:
```ini
[SectionName]
Value1=False
Value2=-1
```
The same text can be deserialised back into the `SomeSettings` object.
## Example
You can also use simple list types as follows:
```csharp
public class Section1
{
public List Values { get; set; } = new List()
{
5,
123,
-1
}
}
public class SomeSettings
{
[IniSection("SectionName")]
public Section1 Section { get; set; } = new Section1();
}
```
You can then serialise it into a INI file format:
```csharp
var text = IniSerialiser.Serialise(new SomeSettings());
```
This will output text as follows:
```ini
[SectionName]
Values=[5,123,-1]
```
The same text can be deserialised back into the `SomeSettings` object.