Skip to content

Default behaviour

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

Default Behavior

  • By default IniWrapper force loading and does not check if file exits.
  • Library by default replace null values with empty string while saving
  • For null complex data type library creates instance of it and save it's default values and apply above rules for each property / field it has.

Note: See also Settings section

Default values

If you want to have default values when reading / saving just initialize property.

public class DefaultValuesConfiguration
{
    public int DefaultInt { get; set; } = DefaultValuesConfigurationConsts.DefaultInt;
    public string DefaultString { get; set; } = DefaultValuesConfigurationConsts.DefaultString;
    public List<int> DefaultList { get; set; } = new List<int>() { 10, 11, 12, 13 };
}

Null values in collections

For collections (IEnumerable and IDictionary) library skips null values while saving.

Example see tests: For given class member

ValueStringDictionary = new Dictionary<int, string>()
{
    [10] = "test",
    [20] = null,
    [25] = "test2"
}

Library writes 10 = test , 25 = test2. Second entity is skipped.

Case 2 cover with tests.

TestStringList = new List<string>()
{
  "a","b",null,"c",null,"d","f"
}

Library writes a,b,c,d,f.

Enums

Enums are by default written / read as int. You can change this behaviour by specifying EnumStringConverter. More information you can find in Custom Converter section.

Bool

Bool value by default is written as True/False string.You can change this behaviour by specifying BoolBinaryConverter. More information you can find in Custom Converter section.

Clone this wiki locally