Easy to use cfg / ini configuration library for .NET.
You can use SharpConfig to read, modify and save configuration files and streams, in either text or binary format.
Minimalistic, fully portable (.NET Standard 2.0), zero package dependencies.
- .NET CLI:
> dotnet add package sharpconfig - Package Manager:
> NuGet\Install-Package sharpconfig - Download latest source
- Download latest binaries
# An example configuration:
[General]
# a comment
SomeString = Hello World!
SomeInteger = 10 # an inline comment
SomeFloat = 20.05
SomeBoolean = true
SomeArray = { 1, 2, 3 }
Day = Monday
[Person]
Name = Peter
Age = 50To read these values, your C# code would look like:
var config = Configuration.LoadFromFile("sample.cfg");
var section = config["General"];
string someString = section["SomeString"].StringValue;
int someInteger = section["SomeInteger"].IntValue;
float someFloat = section["SomeFloat"].FloatValue;
bool someBool = section["SomeBoolean"].BoolValue;
int[] someIntArray = section["SomeArray"].IntValueArray;
string[] someStringArray = section["SomeArray"].StringValueArray;
DayOfWeek day = section["Day"].GetValue<DayOfWeek>();
// Entire user-defined objects can be created from sections and vice versa.
var person = config["Person"].ToObject<Person>();
// ...config["SectionName"]andsection["SettingName"]are create-or-get APIs. If the requested item does not exist, SharpConfig creates it and returns it.GetSectionsNamed()andGetSettingsNamed()useStringComparison.OrdinalIgnoreCaseby default to preserve existing behavior.
var config = new Configuration();
config["General"]["Value"].IntValue = 50;
// Default behavior is case-insensitive.
var matchingSections = config.GetSectionsNamed("general");
// Use StringComparison.Ordinal for case-sensitive matching.
var strictSections = config.GetSectionsNamed("General", StringComparison.Ordinal);The full documentation is available on the website.