TomlNode Class

The base class of the mutable TOML document model: TomlTable, TomlArray, TomlTableArray and TomlValue.

public abstract class TomlNode

Remarks

A node has at most one parent. Use TomlNode.DeepClone to add a copy of a node to another container.

Properties

NameDescription
ParentGets the table or array that contains the node.
RootGets the root of the tree that contains the node.

Gets the table or array that contains the node.

public TomlNode? Parent { get; }

Property value

TomlNode?

Gets the root of the tree that contains the node.

public TomlNode Root { get; }

Property value

TomlNode

Indexers

NameDescription
this[int]Gets or sets the element at an index of the array.
this[string]Gets or sets the value of a key of the table. The getter returns null when the table has no such key.

Item overloads

this[int]

TomlNode.cs

Gets or sets the element at an index of the array.

public TomlNode this[int index] { get; set; }
Parameters
index int
Property value

TomlNode

Exceptions
InvalidOperationException
The node is not an array.

this[string]

TomlNode.cs

Gets or sets the value of a key of the table. The getter returns null when the table has no such key.

public TomlNode? this[string key] { get; set; }
Parameters
key string
Property value

TomlNode?

Exceptions
InvalidOperationException
The node is not a table.

Methods

NameDescription
AsArray()Gets the node as an array.
AsTable()Gets the node as a table.
AsTableArray()Gets the node as an array of tables.
AsValue()Gets the node as a value.
Create(TomlElement)Creates a node from an element of a TomlDocument.
DeepClone()Gets a copy of the node and its descendants, without a parent.
DeepEquals(TomlNode?, TomlNode?)Compares two nodes and their descendants.
GetPath()Gets the path of the node from its root, such as $.servers[0].name.
GetValue<T>()Gets the value of the node converted to T.
GetValueKind()Gets the kind of the value.
ToString()Returns a string that represents the current object.
ToTomlString(Utf8TomlWriterOptions)Gets the TOML text of the node: a document for a table, and a value for the other nodes.
WriteTo(Utf8TomlWriter)Writes the node with a writer: a table as key/value pairs and sub-tables where the writer expects a key, and as an inline table otherwise.

AsArray()

TomlNode.cs

Gets the node as an array.

public TomlArray AsArray()

Returns

TomlArray

Exceptions

InvalidOperationException
The node is not an array.

AsTable()

TomlNode.cs

Gets the node as a table.

public TomlTable AsTable()

Returns

TomlTable

Exceptions

InvalidOperationException
The node is not a table.

AsTableArray()

TomlNode.cs

Gets the node as an array of tables.

public TomlTableArray AsTableArray()

Returns

TomlTableArray

Exceptions

InvalidOperationException
The node is not an array of tables.

AsValue()

TomlNode.cs

Gets the node as a value.

public TomlValue AsValue()

Returns

TomlValue

Exceptions

InvalidOperationException
The node is not a value.

Create(TomlElement)

TomlNode.cs

Creates a node from an element of a TomlDocument.

public static TomlNode Create(TomlElement element)

Parameters

element TomlElement
The element.

Returns

TomlNode

DeepClone()

Gets a copy of the node and its descendants, without a parent.

public abstract TomlNode DeepClone()

Returns

TomlNode

DeepEquals(TomlNode?, TomlNode?)

TomlNode.cs

Compares two nodes and their descendants.

public static bool DeepEquals(TomlNode? node1, TomlNode? node2)

Parameters

node1 TomlNode?
node2 TomlNode?

Returns

bool

Remarks

Tables are equal when they have the same keys with equal values, in any order. Numbers are compared by value, so 1 stored as an Int32 equals 1 stored as a Int64.

GetPath()

TomlNode.cs

Gets the path of the node from its root, such as $.servers[0].name.

public string GetPath()

Returns

string

GetValue<T>()

TomlNode.cs

Gets the value of the node converted to T.

public T GetValue<T>()

Type parameters

T

Returns

T

Exceptions

InvalidOperationException
The node is not a value, or its value cannot be converted.

GetValueKind()

Gets the kind of the value.

public abstract TomlValueKind GetValueKind()

ToString()

TomlNode.cs

Returns a string that represents the current object.

public override string ToString()

Returns

string A string that represents the current object.

ToTomlString(Utf8TomlWriterOptions)

TomlNode.cs

Gets the TOML text of the node: a document for a table, and a value for the other nodes.

public string ToTomlString(Utf8TomlWriterOptions options = default)

Parameters

options Utf8TomlWriterOptions
The options of the writer.

Returns

string

WriteTo(Utf8TomlWriter)

Writes the node with a writer: a table as key/value pairs and sub-tables where the writer expects a key, and as an inline table otherwise.

public abstract void WriteTo(Utf8TomlWriter writer)

Parameters

writer Utf8TomlWriter
The writer.

Operators

NameDescription
explicit operator TomlDateTime(TomlNode)Gets the value of a node.
explicit operator bool(TomlNode)Gets the value of a node.
explicit operator DateOnly(TomlNode)Gets the value of a node.
explicit operator DateTime(TomlNode)Gets the value of a node.
explicit operator DateTimeOffset(TomlNode)Gets the value of a node.
explicit operator decimal(TomlNode)Gets the value of a node.
explicit operator double(TomlNode)Gets the value of a node.
explicit operator int(TomlNode)Gets the value of a node.
explicit operator long(TomlNode)Gets the value of a node.
explicit operator float(TomlNode)Gets the value of a node.
explicit operator string?(TomlNode?)Gets the value of a node.
explicit operator TimeOnly(TomlNode)Gets the value of a node.
implicit operator TomlNode(TomlDateTime)Creates a value node.
implicit operator TomlNode(bool)Creates a value node.
implicit operator TomlNode(DateOnly)Creates a value node.
implicit operator TomlNode(DateTime)Creates a value node.
implicit operator TomlNode(DateTimeOffset)Creates a value node.
implicit operator TomlNode(decimal)Creates a value node.
implicit operator TomlNode(double)Creates a value node.
implicit operator TomlNode(int)Creates a value node.
implicit operator TomlNode(long)Creates a value node.
implicit operator TomlNode(float)Creates a value node.
implicit operator TomlNode(string)Creates a value node.
implicit operator TomlNode(TimeOnly)Creates a value node.

op_Explicit overloads

explicit operator TomlDateTime(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator TomlDateTime(TomlNode value)
Parameters
value TomlNode
Returns

TomlDateTime

explicit operator bool(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator bool(TomlNode value)
Parameters
value TomlNode
Returns

bool

explicit operator DateOnly(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator DateOnly(TomlNode value)
Parameters
value TomlNode
Returns

DateOnly

explicit operator DateTime(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator DateTime(TomlNode value)
Parameters
value TomlNode
Returns

DateTime

explicit operator DateTimeOffset(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator DateTimeOffset(TomlNode value)
Parameters
value TomlNode
Returns

DateTimeOffset

explicit operator decimal(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator decimal(TomlNode value)
Parameters
value TomlNode
Returns

decimal

explicit operator double(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator double(TomlNode value)
Parameters
value TomlNode
Returns

double

explicit operator int(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator int(TomlNode value)
Parameters
value TomlNode
Returns

int

explicit operator long(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator long(TomlNode value)
Parameters
value TomlNode
Returns

long

explicit operator float(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator float(TomlNode value)
Parameters
value TomlNode
Returns

float

explicit operator string?(TomlNode?)

TomlNode.cs

Gets the value of a node.

public static explicit operator string?(TomlNode? value)
Parameters
value TomlNode?
Returns

string?

explicit operator TimeOnly(TomlNode)

TomlNode.cs

Gets the value of a node.

public static explicit operator TimeOnly(TomlNode value)
Parameters
value TomlNode
Returns

TimeOnly

op_Implicit overloads

implicit operator TomlNode(TomlDateTime)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(TomlDateTime value)
Parameters
value TomlDateTime
Returns

TomlNode

implicit operator TomlNode(bool)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(bool value)
Parameters
value bool
Returns

TomlNode

implicit operator TomlNode(DateOnly)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(DateOnly value)
Parameters
value DateOnly
Returns

TomlNode

implicit operator TomlNode(DateTime)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(DateTime value)
Parameters
value DateTime
Returns

TomlNode

implicit operator TomlNode(DateTimeOffset)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(DateTimeOffset value)
Parameters
value DateTimeOffset
Returns

TomlNode

implicit operator TomlNode(decimal)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(decimal value)
Parameters
value decimal
Returns

TomlNode

implicit operator TomlNode(double)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(double value)
Parameters
value double
Returns

TomlNode

implicit operator TomlNode(int)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(int value)
Parameters
value int
Returns

TomlNode

implicit operator TomlNode(long)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(long value)
Parameters
value long
Returns

TomlNode

implicit operator TomlNode(float)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(float value)
Parameters
value float
Returns

TomlNode

implicit operator TomlNode(string)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(string value)
Parameters
value string
Returns

TomlNode

implicit operator TomlNode(TimeOnly)

TomlNode.cs

Creates a value node.

public static implicit operator TomlNode(TimeOnly value)
Parameters
value TimeOnly
Returns

TomlNode