Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simplesoft-pt/iniparser
C# parser for INI files and strings.
https://github.com/simplesoft-pt/iniparser
c-sharp dotnet dotnet-core ini parser
Last synced: 26 days ago
JSON representation
C# parser for INI files and strings.
- Host: GitHub
- URL: https://github.com/simplesoft-pt/iniparser
- Owner: simplesoft-pt
- License: mit
- Created: 2017-01-21T00:08:17.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-15T23:33:40.000Z (almost 8 years ago)
- Last Synced: 2024-11-08T23:47:57.096Z (2 months ago)
- Topics: c-sharp, dotnet, dotnet-core, ini, parser
- Language: C#
- Size: 125 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleSoft.IniParser
Library implemented in .NET using C# that helps developers to deserialize or serialize INI files and strings.
It is compatible with a large range of .NET framework versions, from desktop, to mobile and servers.## Installation
This library can be installed via [NuGet](https://www.nuget.org/packages/SimpleSoft.IniParser) package. Just run the following command:```powershell
Install-Package SimpleSoft.IniParser -Pre
```
The most recent version is in Release Candidate 1. It is considered very stable, just missing some extension methods to make it simpler to manage `IniContainer`, `IniSection` or `IniProperties` instances and compatibility with older PCL.## Compatibility
This library is compatible with the folowing frameworks:
* .NET Framework 4.5
* .NET Core 5.0;
* .NET Standard 1.0;## Usage (Version 1.0.0-rc01)
### Basic example:
```csharp
using System;
using Microsoft.Extensions.Logging;
using SimpleSoft.IniParser.Impl;namespace SimpleSoft.IniParser.Examples
{
public class BasicExample : IExample
{
private readonly ILogger _logger;public BasicExample(ILogger logger)
{
_logger = logger;
}public void Run()
{
const string initialIni = @"
;This is a comment
SomeGP=This is a global property
[SomeSection]
;This is a comment inside a section
SomeSP=This is a property inside a section
[AnotherSection]
;Another comment...
AnotherSP=More?
Response=YES!!!
";
_logger.LogInformation("Initial INI string: '{initialIniString}'", initialIni);_logger.LogDebug("Deserializing string as an IniContainer...");
var deserializer = new IniDeserializer
{
Options = {NormalizeAfterDeserialization = false}
};
var iniContainer = deserializer.DeserializeAsContainer(initialIni);_logger.LogDebug("Normalizing IniContainer...");
var normalizer = new IniNormalizer();
iniContainer = normalizer.Normalize(iniContainer);_logger.LogDebug("Serializing IniContainer as a string...");
var serializer = new IniSerializer
{
Options = {EmptyLineBeforeSection = true, NormalizeBeforeSerialization = false}
};
var finalIni = serializer.SerializeAsString(iniContainer);_logger.LogInformation("Final INI string: " + Environment.NewLine + "'{finalIniString}'", finalIni);
/*
;This is a comment
SOMEGP=This is a global property[SOMESECTION]
;This is a comment inside a section
SOMESP=This is a property inside a section[ANOTHERSECTION]
;Another comment...
ANOTHERSP=More?
RESPONSE=YES!!!
*/
}
}
}```
### Default global properties:
```csharp
using System;
using Microsoft.Extensions.Logging;
using SimpleSoft.IniParser.Impl;namespace SimpleSoft.IniParser.Examples
{
public class DefaultGlobalInstanceExample : IExample
{
private readonly ILogger _logger;public DefaultGlobalInstanceExample(ILogger logger)
{
_logger = logger;
}public void Run()
{
const string initialIni = @"
;This is a comment
SomeGP=This is a global property
[SomeSection]
;This is a comment inside a section
SomeSP=This is a property inside a section
[AnotherSection]
;Another comment...
AnotherSP=More?
Response=YES!!!
";
_logger.LogInformation("Initial INI string: '{initialIniString}'", initialIni);_logger.LogDebug("Deserializing string as an IniContainer...");
var iniContainer = IniDeserializer.Default.DeserializeAsContainer(initialIni);_logger.LogDebug("Normalizing IniContainer...");
iniContainer = IniNormalizer.Default.Normalize(iniContainer);_logger.LogDebug("Serializing IniContainer as a string...");
var finalIni = IniSerializer.Default.SerializeAsString(iniContainer);_logger.LogInformation("Final INI string: " + Environment.NewLine + "'{finalIniString}'", finalIni);
/*
;This is a comment
SOMEGP=This is a global property[SOMESECTION]
;This is a comment inside a section
SOMESP=This is a property inside a section[ANOTHERSECTION]
;Another comment...
ANOTHERSP=More?
RESPONSE=YES!!!
*/
}
}
}```