You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.
@paiden
Hello
Not sure that I specified issue title correctly in context of describing my problem, but anyway
I would like to use Nett for configuration purposes, currently my config file is using such structure:
This is how I load it:
TomlTable _cfg = Toml.ReadFile(filepath)
And this is how I would like to work with it:
var value = ReadInt("Temp.IntVal", 5);
And this is how my ReadInt looks like:
public int ReadInt(in string str, int defVal, bool createIfNone = true)
{
if (!_cfg.ContainsKey(str))
{
if (createIfNone)
_cfg.Add(str, defVal);
return defVal;
}
return _cfg.Get<int>(str);
}
But once I do Toml.WriteFile(_cfg, filepath) on program quit (to save changes made to config file), I get config file with such content:
Tell me please what I do wrong? And how can I see preserve section/keys structure?
Currently I do not use any writes to config file, but was thinking to have WriteInt() like this:
public void WriteInt(in string str, int value) => _cfg.Update(str, value);
and it like: WriteInt("Temp.IntVal", 5)
I guess, this is also wrong way to write values?
The text was updated successfully, but these errors were encountered:
Your ReadInt method does not read the configuration values correctly. It never finds a config value and therefore adds it as a new row to the root table with an escaped key.
The Get methods of a toml table does only work for entries of that table, it will not return values of any sub tables. Therefore it is not valid to use 'dotted' keys as key parameters for this method.
To e.g. get the value of IntValue you would have to do:
@paiden
Hello
Not sure that I specified issue title correctly in context of describing my problem, but anyway
I would like to use Nett for configuration purposes, currently my config file is using such structure:
This is how I load it:
TomlTable _cfg = Toml.ReadFile(filepath)
And this is how I would like to work with it:
var value = ReadInt("Temp.IntVal", 5);
And this is how my ReadInt looks like:
But once I do Toml.WriteFile(_cfg, filepath) on program quit (to save changes made to config file), I get config file with such content:
And this is what I expected to see:
Tell me please what I do wrong? And how can I see preserve section/keys structure?
Currently I do not use any writes to config file, but was thinking to have WriteInt() like this:
public void WriteInt(in string str, int value) => _cfg.Update(str, value);
and it like: WriteInt("Temp.IntVal", 5)
I guess, this is also wrong way to write values?
The text was updated successfully, but these errors were encountered: