A slim, fully managed C# library for reading/writing .ini, .conf, .cfg etc configuration files.
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
and more...
You can support us in a small way, please consider starring and sharing this repo! It helps us getting known and grow the community.
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 project
Install-Package Salaros.ConfigParser
# Add the Salaros.ConfigParser package to a project named [<PROJECT>]
Install-Package Salaros.ConfigParser -ProjectName [<PROJECT>]
// Initialize config file instance from file
var configFileFromPath = new ConfigParser(@"path\to\configfile.cnf");
// Parse text
var configFileFromString = new ConfigParser(@"
[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",
new ConfigParserSettings
{
MultiLineValues = MultiLineValues.Simple | MultiLineValues.AllowValuelessKeys | MultiLineValues.QuoteDelimitedValues,
Culture = new CultureInfo("en-US")
}
);
configFileFromString.GetValue("Strings", "canBeIndented"); // value
configFileFromString["Strings"]["canBeIndented"]; // returns 'value' too
configFileFromString.GetValue("Strings", "andQuoted"); // quotes will be stripped
configFileFromString.GetValue("Numbers", "withD", 0D); // 0,6
configFileFromString.GetValue("Numbers", "dollars", 0D, // 2999
NumberStyles.AllowCurrencySymbol);
configFileFromString.GetValue("Numbers", "dollars"); // $2,999
configFileFromString.GetValue("boolean", "numericTrue", false); // True
configFileFromString.GetValue("boolean", "textFalse", false); // True
configFileFromString.GetValue("boolean", "yesWorks", false); // True
configFileFromString.GetValue("boolean", "upperCaseWorks", false); // True
configFileFromString.GetValue("boolean", "worksAsWell", false); // True
configFileFromString.GetArrayValue("Advanced", "arraysWorkToo"); // ["arrayElement1","arrayElement2"]
configFileFromString.GetValue("Advanced", "valueLessKey"); //
You need Git and .NET Core SDK
git clone https://github.com/salaros/ConfigParser
cd ConfigParser
dotnet build
ConfigParser uses xUnit.net, so you can run unit tests by simply using the following command:
dotnet test tests
ConfigParser is distributed under the MIT license, which grants you
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.