TomlElement Struct
A value of a TomlDocument: a table, an array, or a scalar.
public readonly struct TomlElement : IEquatable<TomlElement>- Implements
Nested types
| Name | Description |
|---|---|
| TomlElement.ArrayEnumerator | Enumerates the elements of an array. |
| TomlElement.TableEnumerator | Enumerates the keys and values of a table. |
Properties
| Name | Description |
|---|---|
| IsArrayOfTables | Gets a value indicating whether the element is an array of tables, defined by [[header]]. |
| IsDottedKeyTable | Gets a value indicating whether the table is created by dotted keys, such as a in a.b = 1. |
| IsImplicitTable | Gets a value indicating whether the table has no header and is only created by the keys of its sub-tables, such as a in [a.b] or a.b = 1. |
| IsInlineTable | Gets a value indicating whether the element is an inline table, such as { a = 1 }. |
| ValueFlags | Gets how the scalar value is written, such as a literal string or a hexadecimal integer. |
| ValueKind | Gets the kind of the element. |
IsArrayOfTables
TomlElement.csIsDottedKeyTable
TomlElement.csIsImplicitTable
TomlElement.csIsInlineTable
TomlElement.csValueFlags
TomlElement.csGets how the scalar value is written, such as a literal string or a hexadecimal integer.
public Utf8TomlTokenFlags ValueFlags { get; }Property value
ValueKind
TomlElement.csIndexers
| Name | Description |
|---|---|
| this[int] | Gets the element at an index of the array. The elements are linked, so the cost is linear in index: prefer TomlElement.EnumerateArray. |
this[int]
TomlElement.csGets the element at an index of the array. The elements are linked, so the cost is linear in index: prefer TomlElement.EnumerateArray.
public TomlElement this[int index] { get; }Parameters
indexint
Property value
Exceptions
InvalidOperationException- The element is not an array.
ArgumentOutOfRangeExceptionindexis outside the array.
Methods
| Name | Description |
|---|---|
| Clone() | Gets a copy of the element that does not depend on the document, so it can be used after the document is disposed. |
| EnumerateArray() | Enumerates the elements of the array. |
| EnumerateTable() | Enumerates the keys and values of the table, in the order of the document. |
| Equals(TomlElement) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object?) | Indicates whether this instance and a specified object are equal. |
| GetArrayLength() | Gets the number of elements of the array. |
| GetBoolean() | Gets the value of a boolean. |
| GetDouble() | Gets the value of a float, or of an integer converted to a Double. |
| GetHashCode() | Returns the hash code for this instance. |
| GetInt64() | Gets the value of an integer. |
| GetProperty(ReadOnlySpan<byte>) | Gets the value of a key of the table. |
| GetProperty(string) | Gets the value of a key of the table. |
| GetPropertyCount() | Gets the number of keys of the table. |
| GetRawText() | Gets the text of the element in the document: a value, an array or an inline table as written, or the header of a table. |
| GetRawUtf8Text() | Gets the UTF-8 text of the element in the document. See TomlElement.GetRawText. |
| GetSourceSpan() | Gets where the element is in the document. The offsets and columns count UTF-16 code units. |
| GetString() | Gets the value of a string. |
| GetTomlDateTime() | Gets the value of a date or a time. |
| ToString() | Gets the text of a string, or the TOML text of other elements. |
| TryGetDecimal(decimal) | Gets the value of a number as a Decimal, parsed from its text to keep its digits. |
| TryGetDouble(double) | Gets the value of a float, or of an integer converted to a Double. |
| TryGetInt32(int) | Gets the value of an integer that fits a Int32. |
| TryGetInt64(long) | Gets the value of an integer. |
| TryGetProperty(ReadOnlySpan<byte>, TomlElement) | Gets the value of a key of the table. |
| TryGetProperty(ReadOnlySpan<char>, TomlElement) | Gets the value of a key of the table. |
| TryGetProperty(string, TomlElement) | Gets the value of a key of the table. |
| TryGetTomlDateTime(TomlDateTime) | Gets the value of a date or a time. |
| ValueEquals(ReadOnlySpan<byte>) | Compares the value of a string to UTF-8 text, without allocating. |
| ValueEquals(ReadOnlySpan<char>) | Compares the value of a string to text, without allocating. |
| ValueEquals(string?) | Compares the value of a string to text, without allocating. |
| WriteTo(Utf8TomlWriter) | Writes the element with a writer. |
Clone()
TomlElement.csGets a copy of the element that does not depend on the document, so it can be used after the document is disposed.
public TomlElement Clone()Returns
EnumerateArray()
TomlElement.csEnumerates the elements of the array.
public TomlElement.ArrayEnumerator EnumerateArray()EnumerateTable()
TomlElement.csEnumerates the keys and values of the table, in the order of the document.
public TomlElement.TableEnumerator EnumerateTable()Equals overloads
Equals(TomlElement)
TomlElement.csIndicates whether the current object is equal to another object of the same type.
public bool Equals(TomlElement other)Parameters
otherTomlElement- An object to compare with this object.
Returns
bool true if the current object is equal to the other parameter; otherwise, false.
Equals(object?)
TomlElement.csGetArrayLength()
TomlElement.csGets the number of elements of the array.
public int GetArrayLength()GetBoolean()
TomlElement.csGets the value of a boolean.
public bool GetBoolean()GetDouble()
TomlElement.csGetHashCode()
TomlElement.csGetInt64()
TomlElement.csGets the value of an integer.
public long GetInt64()GetProperty overloads
GetProperty(ReadOnlySpan<byte>)
TomlElement.csGets the value of a key of the table.
public TomlElement GetProperty(ReadOnlySpan<byte> utf8PropertyName)Parameters
utf8PropertyNameReadOnlySpan<byte>
Returns
Exceptions
InvalidOperationException- The element is not a table.
KeyNotFoundException- The table has no such key.
GetProperty(string)
TomlElement.csGets the value of a key of the table.
public TomlElement GetProperty(string propertyName)Parameters
propertyNamestring
Returns
Exceptions
InvalidOperationException- The element is not a table.
KeyNotFoundException- The table has no such key.
GetPropertyCount()
TomlElement.csGets the number of keys of the table.
public int GetPropertyCount()GetRawText()
TomlElement.csGetRawUtf8Text()
TomlElement.csGets the UTF-8 text of the element in the document. See TomlElement.GetRawText.
public ReadOnlySpan<byte> GetRawUtf8Text()Returns
GetSourceSpan()
TomlElement.csGets where the element is in the document. The offsets and columns count UTF-16 code units.
public TomlSourceSpan? GetSourceSpan()Returns
TomlSourceSpan? The location of the value, or of the key of a table without a header; null for the root table.
GetString()
TomlElement.csGets the value of a string.
public string GetString()GetTomlDateTime()
TomlElement.csGets the value of a date or a time.
public TomlDateTime GetTomlDateTime()ToString()
TomlElement.csTryGetDecimal(decimal)
TomlElement.csTryGetDouble(double)
TomlElement.csTryGetInt32(int)
TomlElement.csTryGetInt64(long)
TomlElement.csTryGetProperty overloads
TryGetProperty(ReadOnlySpan<byte>, TomlElement)
TomlElement.csGets the value of a key of the table.
public bool TryGetProperty(ReadOnlySpan<byte> utf8PropertyName, out TomlElement value)Parameters
utf8PropertyNameReadOnlySpan<byte>valueTomlElement
Returns
Exceptions
InvalidOperationException- The element is not a table.
TryGetProperty(ReadOnlySpan<char>, TomlElement)
TomlElement.csGets the value of a key of the table.
public bool TryGetProperty(ReadOnlySpan<char> propertyName, out TomlElement value)Parameters
propertyNameReadOnlySpan<char>valueTomlElement
Returns
Exceptions
InvalidOperationException- The element is not a table.
TryGetProperty(string, TomlElement)
TomlElement.csGets the value of a key of the table.
public bool TryGetProperty(string propertyName, out TomlElement value)Parameters
propertyNamestringvalueTomlElement
Returns
Exceptions
InvalidOperationException- The element is not a table.
TryGetTomlDateTime(TomlDateTime)
TomlElement.csGets the value of a date or a time.
public bool TryGetTomlDateTime(out TomlDateTime value)ValueEquals overloads
ValueEquals(ReadOnlySpan<byte>)
TomlElement.csCompares the value of a string to UTF-8 text, without allocating.
public bool ValueEquals(ReadOnlySpan<byte> utf8Text)Parameters
utf8TextReadOnlySpan<byte>
Returns
Exceptions
InvalidOperationException- The element is not a string.
ValueEquals(ReadOnlySpan<char>)
TomlElement.csCompares the value of a string to text, without allocating.
public bool ValueEquals(ReadOnlySpan<char> text)Parameters
textReadOnlySpan<char>
Returns
Exceptions
InvalidOperationException- The element is not a string.
ValueEquals(string?)
TomlElement.csCompares the value of a string to text, without allocating.
WriteTo(Utf8TomlWriter)
TomlElement.Write.csWrites the element with a writer.
public void WriteTo(Utf8TomlWriter writer)Parameters
writerUtf8TomlWriter- The writer.
Remarks
A table that is not inline, written where the writer expects a key, is written as key/value pairs followed by its sub-tables, with headers relative to the table. Otherwise the element is written as a value: a table as an inline table, and an array of tables as an array of inline tables.
The values are copied as written in the document, except the TOML 1.1 syntax, which is written as TOML 1.0: the keys of a table defined by dotted keys are written under a header, and strings with escape sequences are encoded again.
Operators
| Name | Description |
|---|---|
| operator ==(TomlElement, TomlElement) | Compares two elements. |
| operator !=(TomlElement, TomlElement) | Compares two elements. |
operator ==(TomlElement, TomlElement)
TomlElement.csCompares two elements.
public static bool operator ==(TomlElement left, TomlElement right)operator !=(TomlElement, TomlElement)
TomlElement.csCompares two elements.
public static bool operator !=(TomlElement left, TomlElement right)