Skip to content

How does library work?

Piotr Szkudlarski edited this page Dec 11, 2018 · 2 revisions

For given configuration class:

public struct TestConfiguration
{
   public string TestString { get; set; }
   public List<int> TestIntList { get; set; }
}

IniWrapper will call IIniParser with following ini parameters Section : TestConfiguration, Key : TestString, Value : value in TestString property.

Overall rules:

  • Section is evaluated from class / struct name
  • Key is evaluated from property / field name
  • Value is taken from property / field value

Exception is for IDictionary type:

  • Section is evaluated from property / field name
  • Key is taken from Key (from IDictionary)
  • Value is taken from Value (from IDictionary)

For complex types for example:

public class ComplexTestConfiguration
{
   public TestConfiguration TestConfiguration { get; set; }
}

public struct TestConfiguration
{
   public string TestString { get; set; }
   public List<int> TestIntList { get; set; }
}

IniWrapper will call IIniParser with following ini parameters Section : TestConfiguration, Key : TestString, Value : value in TestString. It will be the same as writing / reading directly TestConfiguration class.

Handling IEnumerable of complex types

Library will add _index postfix to section (e.g TestConfiguration_0, TestConfiguration_1). While reading library calls IniParser.Read(Section, null) method with null key to check if section exists if not library stops reading. If you are using custom parser make sure that this calls return not null and not empty value for existing sections.

Clone this wiki locally