TomlDocumentSyntax Class
A whole TOML document.
public sealed class TomlDocumentSyntax : TomlSyntaxNodeRemarks
The entries are flat, as they are in the text: a table header is followed by the key/value pairs under it, not their parent. TomlDocumentSyntax.RootProperties and TomlTableSyntax.Properties group them.
- Inheritance
TomlSyntaxNodeTomlDocumentSyntax
Properties
| Name | Description |
|---|---|
| EndOfFileToken | |
| Entries | Gets the table headers, key/value pairs, and skipped lines, in source order. |
| RootProperties | Gets the key/value pairs of the root table: the ones before the first table header. |
| Tables | Gets the table and array-of-tables headers, in source order. |
EndOfFileToken
TomlDocumentSyntax.csEntries
TomlDocumentSyntax.csGets the table headers, key/value pairs, and skipped lines, in source order.
public SyntaxList<TomlEntrySyntax> Entries { get; }Property value
RootProperties
TomlDocumentSyntax.csGets the key/value pairs of the root table: the ones before the first table header.
public IReadOnlyList<TomlPropertySyntax> RootProperties { get; }Property value
Tables
TomlDocumentSyntax.csGets the table and array-of-tables headers, in source order.
public IEnumerable<TomlTableSyntax> Tables { get; }Property value
Methods
| Name | Description |
|---|---|
| Accept(TomlSyntaxVisitor) | |
| Accept<TResult>(TomlSyntaxVisitor<TResult>) | |
| AddEntries(TomlEntrySyntax[]) | Returns this document with items added at the end. |
| GetKeyValues() | Gets every key/value pair of the document, in source order, with the full key each one defines. |
| GetValue(string[]) | Gets the value of the key/value pair that defines the full key names. |
| Update(SyntaxList<TomlEntrySyntax>, SyntaxToken) | Returns this document with the given parts, or itself when nothing changed. |
| WithEndOfFileToken(SyntaxToken) | |
| WithEntries(SyntaxList<TomlEntrySyntax>) |
Accept overloads
Accept(TomlSyntaxVisitor)
TomlDocumentSyntax.cspublic override void Accept(TomlSyntaxVisitor visitor)Parameters
visitorTomlSyntaxVisitor
No documentation is available.
Accept<TResult>(TomlSyntaxVisitor<TResult>)
TomlDocumentSyntax.cspublic override TResult? Accept<TResult>(TomlSyntaxVisitor<TResult> visitor)No documentation is available.
AddEntries(TomlEntrySyntax[])
TomlDocumentSyntax.csReturns this document with items added at the end.
public TomlDocumentSyntax AddEntries(params TomlEntrySyntax[] items)Parameters
itemsTomlEntrySyntax[]
Returns
Remarks
Every entry has to end its line, so a line feed is added after the last entry and after each of items that does not already end with a line break.
Comments after the last entry belong to the end of the document, so the new entries go before them. In a document that has only comments, such as a header, they go after them instead.
GetKeyValues()
TomlDocumentSyntax.csGets every key/value pair of the document, in source order, with the full key each one defines.
public IEnumerable<TomlKeyValue> GetKeyValues()Returns
Remarks
A key/value pair whose value is an inline table comes first, followed by the pairs of that inline table, each with the full key it defines. The values in an array are not visited, as they have no key of their own.
The pairs are read as they are written, whatever the diagnostics of the document: a key defined twice comes twice.
Example
var document = TomlSyntaxTree.ParseText("""
[dependencies]
serde = "1.0"
tokio = "1.2"
""").GetRoot();
var dependencies = new List<string>();
foreach (var pair in document.GetKeyValues())
{
if (pair.Names is ["dependencies", var name] && pair.Value is TomlStringSyntax version)
{
dependencies.Add($"{name} {version.Value}");
}
}
Assert.Equal(["serde 1.0", "tokio 1.2"], dependencies);GetValue(string[])
TomlDocumentSyntax.csGets the value of the key/value pair that defines the full key names.
public TomlValueSyntax? GetValue(params string[] names)Parameters
namesstring[]- The name of each part of the key, unquoted.
Returns
TomlValueSyntax? The value, or null when no key/value pair defines that key.
Exceptions
ArgumentNullExceptionnamesor one of its items isnull.ArgumentExceptionnamesis empty.
Remarks
The key is looked for wherever it can be written: under a header, as a dotted key, or in an inline table, so GetValue("server", "port") finds the port in [server], in server.port = 80, and in server = { port = 80 }. Names are compared as they are, case included, as TOML does. A table a header defines is not a value. When the key is defined more than once, as it is in each table of an array of tables, the first one is returned.
Update(SyntaxList<TomlEntrySyntax>, SyntaxToken)
TomlDocumentSyntax.csReturns this document with the given parts, or itself when nothing changed.
public TomlDocumentSyntax Update(SyntaxList<TomlEntrySyntax> entries, SyntaxToken endOfFileToken)WithEndOfFileToken(SyntaxToken)
TomlDocumentSyntax.cspublic TomlDocumentSyntax WithEndOfFileToken(SyntaxToken endOfFileToken)No documentation is available.
WithEntries(SyntaxList<TomlEntrySyntax>)
TomlDocumentSyntax.cspublic TomlDocumentSyntax WithEntries(SyntaxList<TomlEntrySyntax> entries)No documentation is available.