Closed frankhommers closed 1 year ago
Hi!
The first document displays a table-array, i.e. an array of tables. Tomlet maps each table to its own .NET object, so you can think of this as an array of objects. In this case, there's one root-level key, fruit
, which would defined as an array of fruit objects. The equivalent c# would be something like
public class FruitDocumentRoot
{
public Fruit[] fruit;
}
public class Fruit
{
public string name;
public Geometry geometry;
public Color[] color;
public class Geometry
{
public string shape; //Or could be a 'shape' enum!
public string note;
}
public class Color
{
public string name;
public string note
}
}
The second example is of course much simpler:
public class ServersDocumentRoot
{
public Servers servers; //Or even, 'Dictionary<string, Server>'!
}
public class Servers
{
public Server alpha;
public Server beta;
}
public class Server
{
public string ip;
public string role; //Or a 'Role' enum!
}
In both cases, the potentially-confusing part is that you need a data type to represent the root of the document, with it having a single key - servers
or fruit
.
Hope this helps!
Yes this helps a lot! Thank you!
Hi there,
I love your lib, I think it's the best dotnet lib for parsing .toml files. But I am struggling with the deserialization a bit. What would be the matching poco's of this structure?
Or even this:
I can't really figure it out by looking at your tests. It might help others as well to put the answer in README.md ;-)