dezhidki / Tommy

A single-file TOML reader and writer for C#
MIT License
212 stars 16 forks source link

Using an indexer on Table result in error #42

Open MBCD2000 opened 1 year ago

MBCD2000 commented 1 year ago

Thank you for this nice peace of software!

I tried to get a row from a table by indexing it, this resulted in a null:

var settingsTable= tml["Einstellungen"].AsTable; var tableRow= settingsTable[0];

There should be a possibility to use an indexer to get the key and its value, like an Dictionary returns it. With strings this works fine, but integers results into null, but I expected to get something 😉

I added this code to the TomlTable to fix this:

public new KeyValuePair<string, TomlNode> this[int index] { get { if (index > RawTable.Count) return new KeyValuePair<string, TomlNode>(); return RawTable.ElementAt(index); } set { if (index > RawTable.Count) return; RawTable[RawTable.ElementAt(index).Key] = value!.Value; } }