Skip to content

Repository files navigation

ConfigParser Build statusAppVeyor tests branchCoverage Status

GitHub top language.NET Standard.NET Standard.NET Framework

LicenseNuGetNuGet Pre ReleaseNuGet

Donate PatreonDonate PaypalDonate Liberapay

ConfigParser - is a slim, cross-platform, fully managed C# library for reading and writing .ini, .conf, .cfg etc configuration files.

You could use it in your Unity 3D, Xamarin (iOS & Android), .NET Framework applications (even with old 4.0/4.5), .NET Core CLI and ASP.NET Core applications, Mono etc

Features

Customization

  • customizable encoding (most encodings can be auto-detected)
  • customizable culture
  • customizable number styles (e.g. currencies, exponential notation etc)
  • customizable line endings (usually auto-detected)
  • customizable true and false (e.g. "verum" / "falsum" )
  • customizable comment characters
  • customizable key/value separator (defaults to '=')

Read and preserved

  • file header comments
  • config files with no sections (like in this [SectionName]) or even mixed: first section has no header, just keys
  • comments in general
  • section comments
  • empty lines
  • indented sections
  • indented keys
  • indented values

Values

  • default values
  • multi-line values (both quoted and not)
  • quoted values
  • null values (value-less keys)
  • array values
  • fancy float / double
  • byte-encoded values
  • smart boolean values (0/1, on/off, enabled/disabled work of the box)

and more...

🟊🟊🟊 Support this project 🟊🟊🟊

You can support us in a small way, please consider starring and sharing this repo! It helps us getting known and grow the community.

star us

Installation

Config Parser can be installed via NuGet by using Package Manager in your IDE, dotnet binary or Package Console

# Add the Salaros.ConfigParser package to a project named [<PROJECT>]
dotnet add [<PROJECT>] package Salaros.ConfigParser

or Visual Studio's Package Console

# Add the Salaros.ConfigParser package to the default projectInstall-Package Salaros.ConfigParser
# Add the Salaros.ConfigParser package to a project named [<PROJECT>]Install-Package Salaros.ConfigParser -ProjectName [<PROJECT>]

Usage

// Initialize config file instance from filevarconfigFileFromPath=newConfigParser(@"path\to\configfile.cnf");// Parse textvarconfigFileFromString=newConfigParser(@" [Strings] canBeIndented = value andQuoted = ""quotes will be stripped"" [Numbers] withD = 0.6D dollars = $2,999 [boolean] numericTrue = 1 textFalse = true yesWorks = yes upperCaseWorks = on worksAsWell = Enabled [Advanced] arrayWorkToo = arrayElement1 arrayElement2 valueLessKey",newConfigParserSettings{MultiLineValues=MultiLineValues.Simple|MultiLineValues.AllowValuelessKeys|MultiLineValues.QuoteDelimitedValues,Culture=newCultureInfo("en-US")});configFileFromString.GetValue("Strings","canBeIndented");// valueconfigFileFromString["Strings"]["canBeIndented"];// returns 'value' tooconfigFileFromString.GetValue("Strings","andQuoted");// quotes will be strippedconfigFileFromString.GetValue("Numbers","withD",0D);// 0,6configFileFromString.GetValue("Numbers","dollars",0D,// 2999NumberStyles.AllowCurrencySymbol);configFileFromString.GetValue("Numbers","dollars");// $2,999configFileFromString.GetValue("boolean","numericTrue",false);// TrueconfigFileFromString.GetValue("boolean","textFalse",false);// TrueconfigFileFromString.GetValue("boolean","yesWorks",false);// TrueconfigFileFromString.GetValue("boolean","upperCaseWorks",false);// TrueconfigFileFromString.GetValue("boolean","worksAsWell",false);// TrueconfigFileFromString.GetArrayValue("Advanced","arraysWorkToo");// ["arrayElement1","arrayElement2"]configFileFromString.GetValue("Advanced","valueLessKey");//

How to build

You need Git and .NET Core SDK

git clone https://github.com/salaros/ConfigParser
cd ConfigParser
dotnet build

How to test

ConfigParser uses xUnit.net, so you can run unit tests by simply using the following command:

dotnet test tests

License

ConfigParser is distributed under the MIT license, which grants you

  • Private use
  • Commercial use
  • Modification
  • Distribution

However you have to include the content of license file in your source code (if you distribute your Software in text form), otherwise include it in your own LICENSE file or to some sort of About -> Open-source libraries section if you distribute your Software as a compiled library / binary. Here is why (part of MIT license):

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

About

A slim, fully managed C# library for reading/writing .ini, .conf, .cfg etc configuration files.

Topics

Resources

Stars

124 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages