Skip to content

Quick start

Szpi edited this page Jul 22, 2018 · 3 revisions

Loading configuration

You can use custom IniParser class by passing it in Create Method in IniWrapperFactory class. Then call LoadConfiguration method with class that IniWrapper should discover and bind values.

    var iniWrapperFactory = new IniWrapperFactory();
    var iniWrapper = iniWrapperFactory.Create(new CustomIniParser());
    
    var loadedIniConfiguration = iniWrapper.LoadConfiguration<TestConfiguration>();

If you want to use default IniParser you can call CreateWithDefaultIniParser method. By doing this library will create IniParser that wraps Windows C++ methods from kernel. For more information see Microsoft documentation for WritePrivateProfileString, GetPrivateProfileString and GetPrivateProfileSection and IniParser.cs.

var iniWrapperFactory = new IniWrapperFactory();
var iniWrapper = iniWrapperFactory.CreateWithDefaultIniParser(x =>
{
    x.IniFilePath = "test.ini";
});

var loadedIniConfiguration = iniWrapper.LoadConfiguration<TestConfiguration>();

For more information about Settings please go to Settings.

Note: In version 1.1.0 and 1.0.0 you have to call IniWrapperFactory with CreateWithDefaultIniWrapper.

var iniWrapper = iniWrapperFactory.CreateWithDefaultIniWrapper("test.ini");

Saving configuration

To save configuration just call Save method and pass configuration class.

var iniWrapperFactory = new IniWrapperFactory();
var iniWrapper = iniWrapperFactory.CreateWithDefaultIniParser(x =>
{
    x.IniFilePath = "test.ini";
});

iniWrapper.SaveConfiguration(new TestConfiguration());
Clone this wiki locally