Skip to content

Settings

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

How to use?

Use lambda to configure ini settings.

var iniWrapper = new IniWrapperFactory().Create(iniSettings =>
{
  iniSettings.MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad;
  iniSettings.EnumerableEntitySeparator = '*';
  iniSettings.IniFilePath = "test.ini";
  iniSettings.NullValueHandling = NullValueHandling.ReplaceWithEmptyString;
  iniSettings.DefaultIniWrapperBufferSize = 1024;
}, iniParser);

You can also pass IniSettings instance.

var inisettings = new IniSettings()
{
 MissingFileWhenLoadingHandling = MissingFileWhenLoadingHandling.ForceLoad,
 EnumerableEntitySeparator = '*',
 IniFilePath = "inipath.ini",
 NullValueHandling = NullValueHandling.ReplaceWithEmptyString,
 DefaultIniWrapperBufferSize = 1024,
};

var iniWrapper = new IniWrapperFactory().Create(inisettings, iniParser);

Default values

 public class IniSettings : IIniSettings
 {
     public char EnumerableEntitySeparator { get; set; } = ',';
     public string IniFilePath { get; set; }
     public MissingFileWhenLoadingHandling MissingFileWhenLoadingHandling { get; set; } = MissingFileWhenLoadingHandling.ForceLoad;
     public NullValueHandling NullValueHandling { get; set; } = NullValueHandling.ReplaceWithEmptyString;
     public int DefaultIniWrapperBufferSize { get; set; } = 1024;
 }

Configuration of IniSettings

MissingFileWhenLoadingHandling

Configuration of handling situation when file is missing or FilePath is not set.

ForceLoad

  • Library will not check if file exists. It will always try to load from file.

DoNotLoad

  • If file is missing library will return instance of given configuration class. It won't neither write nor read anything from file.

CreateWithDefaultValues

  • If file is missing library will create instance of given configuration class save it to file and return instance. Note: IniFilePath has to be set.

IniFilePath

IniFilePath is necessary when MissingFileWhenLoadingHandling is set to DoNotLoad or CreateWithDefaultValues. Library needs it to determine if file is missing even if you are using custom IIniParser.

EnumerableEntitySeparator

You can specify IEnumerable separator. If '*' is set and given configuration model

var config = new TestConfiguration()
{
 TestStringList = new List<string>()
 {
     "a","b","c","d","f"
 },
};

Library will write to file "a*b*c*d*f".

NullValueHandling

Ignore

  • Null values will be not written.

ReplaceWithEmptyString

  • Null values will be replaced with empty string, for complex types library will create instance of it and write it.

DefaultIniWrapperBufferSize

When using CreateWithDefaultIniParser you can specify buffer size that this class uses while reading from file. Only valid when default IIniparser is used. see more in IniParser.cs