Skip to content
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

Is there any way to retrieve the line ? #70

Open
JeanArhancet opened this issue Aug 18, 2023 · 3 comments
Open

Is there any way to retrieve the line ? #70

JeanArhancet opened this issue Aug 18, 2023 · 3 comments
Labels
question Further information is requested

Comments

@JeanArhancet
Copy link

Hey there,

Thanks for your awesome Toml parser.

Is there a way to retrieve the line in which a toml element is located? For example, how can I find out the list line?

var toml = @"global = ""this is a string""
# This is a comment of a table
[my_table]
key = 1 # Comment a key
value = true
list = [4, 5, 6]
";

// Converts the TOML string to a `TomlTable`
var model = Toml.ToModel(toml);
// Prints "this is a string"
Console.WriteLine(model["global"]);

Is it possible to retrieve a line from a tomlArray...etc?

@xoofx xoofx added the question Further information is requested label Sep 8, 2023
@xoofx
Copy link
Owner

xoofx commented Sep 8, 2023

Line is accessible by parsing (but not converting to a model) and then through DocumentSyntax, you can access the Span property of the various elements. The model is a step that is compressing the information and would not be able to recover all the details that you get through the syntax model.

@lilith
Copy link
Contributor

lilith commented Jan 30, 2024

#69 might help, although you'll have to add public TomlPropertiesMetadata? PropertiesMetadata { get; set; } to your classes.

@lilith
Copy link
Contributor

lilith commented Jan 31, 2024

TomlTable.PropertiesMetadata.TryGetProperty provides TomlPropertyMetadata which has .Span, which is a SourceSpan. This will give you the line for list. This was added to main recently, so probably the next release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants