-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we get node key name from itself? #2
Comments
You can either use |
Hi @alexclooze But I think we can have nodeName inside the node instance so that we only need to call: For example, I use Tommy in my code generation engine so I need to generate class from a node, which class name is the node name. In the runtime of the generation process, it is hard to tell exactly what is the node name is. In some other language like LUA, I can assign nodeName to node like this: |
I know this is an old thread... First, thanks to @akluth for the great library! It is simple, straightforward, well commented, and easy to use. VERY nice! In case others look here, I wanted to post an easy solution that works with the library as is. Like @takaaptech I wanted to iterate over a Table, and get the Key and Value together. The quick way I came up with is to just iterate over the underlying Dictionary, which is held in the public RawTable node property for Table type nodes. // Iterating over the RawTable Dictionary yields a KeyValuePair<string, TomlNode>.
// You can access the name of the node as .Key, and the value (the node itself) as .Value.
foreach (var ITEM in TBL.RawTable)
Console.WriteLine($"Key: {ITEM.Key}, Value: {ITEM.Value}"); You could pass around this KeyValuePair<> ITEM for further processing. I think the reason the "name" is not part of the node itself is because only nodes that are inside a Table/Dictionary have keys (names), and those "names" are stored only as keys in the parent/container dictionary. Items in an array, for instance, have no names, so having a .Name as part of every node might not make sense. Thanks again! |
Hi @dezhidki ,
Thank so much for this TOML parser library! It is awesome!
For now, each time working with TomlNode, I need to get its key name.
For example:
I can get TomlTable by:
Thanks!
The text was updated successfully, but these errors were encountered: