-
Notifications
You must be signed in to change notification settings - Fork 0
Settings
Piotr Szkudlarski edited this page Dec 11, 2018
·
9 revisions
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);
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 handling situation when file is missing or FilePath is not set.
- Library will not check if file exists. It will always try to load from file.
- If file is missing library will return instance of given configuration class. It won't neither write nor read anything from file.
- 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 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.
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".
- Null values will be not written.
- Null values will be replaced with empty string, for complex types library will create instance of it and write it.
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