TomlDocumentSyntax Class

A whole TOML document.

public sealed class TomlDocumentSyntax : TomlSyntaxNode

Remarks

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
TomlSyntaxNode TomlDocumentSyntax

Properties

NameDescription
EndOfFileToken
EntriesGets the table headers, key/value pairs, and skipped lines, in source order.
RootPropertiesGets the key/value pairs of the root table: the ones before the first table header.
TablesGets the table and array-of-tables headers, in source order.

EndOfFileToken

TomlDocumentSyntax.cs
public SyntaxToken EndOfFileToken { get; }

Property value

SyntaxToken

No documentation is available.

Gets the table headers, key/value pairs, and skipped lines, in source order.

public SyntaxList<TomlEntrySyntax> Entries { get; }

RootProperties

TomlDocumentSyntax.cs

Gets the key/value pairs of the root table: the ones before the first table header.

public IReadOnlyList<TomlPropertySyntax> RootProperties { get; }

Gets the table and array-of-tables headers, in source order.

public IEnumerable<TomlTableSyntax> Tables { get; }

Methods

NameDescription
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.cs
public override void Accept(TomlSyntaxVisitor visitor)
Parameters
visitor TomlSyntaxVisitor

No documentation is available.

Accept<TResult>(TomlSyntaxVisitor<TResult>)

TomlDocumentSyntax.cs
public override TResult? Accept<TResult>(TomlSyntaxVisitor<TResult> visitor)
Type parameters
TResult
Parameters
visitor TomlSyntaxVisitor<TResult>
Returns

TResult?

No documentation is available.

AddEntries(TomlEntrySyntax[])

TomlDocumentSyntax.cs

Returns this document with items added at the end.

public TomlDocumentSyntax AddEntries(params TomlEntrySyntax[] items)

Parameters

items TomlEntrySyntax[]

Returns

TomlDocumentSyntax

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.cs

Gets every key/value pair of the document, in source order, with the full key each one defines.

public IEnumerable<TomlKeyValue> GetKeyValues()

Returns

IEnumerable<TomlKeyValue>

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.cs

Gets the value of the key/value pair that defines the full key names.

public TomlValueSyntax? GetValue(params string[] names)

Parameters

names string[]
The name of each part of the key, unquoted.

Returns

TomlValueSyntax? The value, or null when no key/value pair defines that key.

Exceptions

ArgumentNullException
names or one of its items is null.
ArgumentException
names is 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.cs

Returns this document with the given parts, or itself when nothing changed.

public TomlDocumentSyntax Update(SyntaxList<TomlEntrySyntax> entries, SyntaxToken endOfFileToken)

Parameters

entries SyntaxList<TomlEntrySyntax>
endOfFileToken SyntaxToken

Returns

TomlDocumentSyntax

WithEndOfFileToken(SyntaxToken)

TomlDocumentSyntax.cs
public TomlDocumentSyntax WithEndOfFileToken(SyntaxToken endOfFileToken)

Parameters

endOfFileToken SyntaxToken

Returns

TomlDocumentSyntax

No documentation is available.

WithEntries(SyntaxList<TomlEntrySyntax>)

TomlDocumentSyntax.cs
public TomlDocumentSyntax WithEntries(SyntaxList<TomlEntrySyntax> entries)

No documentation is available.