Table of Contents

Class TomlToken

Namespace
RStein.TOML
Assembly
RStein.TOML.dll

Abstract base class for all TOML tokens (tables, arrays, keys, values, etc.).

public abstract class TomlToken : IEnumerable<TomlToken>, IEnumerable
Inheritance
TomlToken
Implements
Derived
Inherited Members

Remarks

TomlToken is the root of the TOML object model hierarchy. All TOML elements (tables, arrays, keys, values) derive from this class. It implements IEnumerable<T> to provide iteration over child tokens. The TokenType property indicates the specific kind of token. Supports indexed access via both integer indexing (for TomlArray and TomlTable) and string/key indexing (for TomlTable). Provides explicit cast operators to common .NET types for type conversion of primitive values.

Constructors

TomlToken(TomlTokenType)

Initializes a new instance of the TomlToken.

protected TomlToken(TomlTokenType tokenType)

Parameters

tokenType TomlTokenType

Properties

this[TomlKey]

Gets or sets the value associated with the specified key using a TomlKey.

public virtual TomlToken this[TomlKey key] { get; set; }

Parameters

key TomlKey

The key as a TomlKey object.

Property Value

TomlToken

The value associated with the key.

Exceptions

InvalidOperationException

The TomlToken does not support the operation.

this[int]

Gets or sets the value at the specified index.

public virtual TomlToken this[int index] { get; set; }

Parameters

index int

The zero-based index of the element.

Property Value

TomlToken

The value at the specified index.

Exceptions

InvalidOperationException

The TomlToken does not support the operation.

this[string]

Gets or sets the value associated with the specified key using a string key.

public virtual TomlToken this[string key] { get; set; }

Parameters

key string

The key as a string.

Property Value

TomlToken

The value associated with the key.

Exceptions

InvalidOperationException

The TomlToken does not support the operation.

TokenType

Gets the TomlToken type.

public TomlTokenType TokenType { get; }

Property Value

TomlTokenType

Tokens

Gets the enumerator that enumerates child TomlToken instances belonging to the current token.

public IEnumerable<TomlToken> Tokens { get; }

Property Value

IEnumerable<TomlToken>

Methods

DeepEqualsAsync(TomlToken?)

Asynchronously determines whether the current TomlToken instance is deeply equal to another TomlToken instance, performing a recursive structural comparison of all nested elements and values.

public virtual Task<bool> DeepEqualsAsync(TomlToken? other)

Parameters

other TomlToken

The TomlToken instance to compare with the current instance. Can be null, in which case the method returns false unless the current instance is also null.

Returns

Task<bool>

A Task<TResult> of bool that represents the asynchronous comparison operation. The task result is true if the current instance is structurally and deeply equal to other; otherwise, false.

Remarks

Unlike a shallow equality check, this method traverses the entire token tree recursively, comparing each child token, key, and value to ensure complete structural equivalence.

GetChildren()

Enumerates all children of this TomlToken.

protected virtual IEnumerable<TomlToken> GetChildren()

Returns

IEnumerable<TomlToken>

GetEnumerator()

public IEnumerator<TomlToken> GetEnumerator()

Returns

IEnumerator<TomlToken>

SerializeToStringAsync()

Asynchronously serializes the current TomlToken instance into its TOML-compliant string representation.

public virtual Task<string> SerializeToStringAsync()

Returns

Task<string>

A Task<TResult> of string representing the asynchronous serialization operation. The task result contains the full TOML-formatted string of the current token and all its nested elements.

Operators

explicit operator bool?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable bool.

public static explicit operator bool?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

bool?

An bool containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid bool value.

explicit operator byte?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable byte.

public static explicit operator byte?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

byte?

An byte containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid byte value.

explicit operator char?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable char.

public static explicit operator char?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

char?

An char containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid char value.

explicit operator DateTime?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable DateTime.

public static explicit operator DateTime?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

DateTime?

An DateTime containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid DateTime value.

explicit operator decimal?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable decimal.

public static explicit operator decimal?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

decimal?

An decimal containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid decimal value.

explicit operator double?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable double.

public static explicit operator double?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

double?

An double containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid double value.

explicit operator Guid?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable Guid.

public static explicit operator Guid?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

Guid?

An Guid containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid Guid value.

explicit operator short?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable short.

public static explicit operator short?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

short?

An short containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid short value.

explicit operator int?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable int.

public static explicit operator int?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

int?

An int containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid integer value.

explicit operator long?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable long.

public static explicit operator long?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

long?

An long containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid long value.

explicit operator sbyte?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable sbyte.

public static explicit operator sbyte?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

sbyte?

An sbyte containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid sbyte value.

explicit operator float?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable float.

public static explicit operator float?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

float?

An float containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid float value.

explicit operator ushort?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable ushort.

public static explicit operator ushort?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

ushort?

An ushort containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid ushort value.

explicit operator uint?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable uint.

public static explicit operator uint?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

uint?

An uint containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid uint value.

explicit operator ulong?(TomlToken?)

Explicitly converts a TomlToken instance to a nullable ulong.

public static explicit operator ulong?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

ulong?

An ulong containing the value of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken does not represent a valid ulong value.

explicit operator string?(TomlToken?)

Explicitly converts a TomlToken instance to its string representation.

public static explicit operator string?(TomlToken? tomlToken)

Parameters

tomlToken TomlToken

The TomlToken to convert. Can be null.

Returns

string

A string containing the TOML representation of tomlToken, or null if tomlToken is null.

Exceptions

InvalidCastException

Thrown if tomlToken cannot be represented as a valid TOML string.

implicit operator TomlToken(bool)

Implicitly converts a bool value to a TomlToken instance.

public static implicit operator TomlToken(bool value)

Parameters

value bool

The bool value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(byte)

Implicitly converts a byte value to a TomlToken instance.

public static implicit operator TomlToken(byte value)

Parameters

value byte

The byte value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(DateTime)

Implicitly converts a DateTime value to a TomlToken instance.

public static implicit operator TomlToken(DateTime value)

Parameters

value DateTime

The DateTime value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(decimal)

Implicitly converts a decimal value to a TomlToken instance.

public static implicit operator TomlToken(decimal value)

Parameters

value decimal

The decimal value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(double)

Implicitly converts a double value to a TomlToken instance.

public static implicit operator TomlToken(double value)

Parameters

value double

The double value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(Guid)

Implicitly converts a Guid value to a TomlToken instance.

public static implicit operator TomlToken(Guid value)

Parameters

value Guid

The Guid value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(short)

Implicitly converts a short value to a TomlToken instance.

public static implicit operator TomlToken(short value)

Parameters

value short

The short value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(int)

Implicitly converts a int value to a TomlToken instance.

public static implicit operator TomlToken(int value)

Parameters

value int

The int value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(long)

Implicitly converts a long value to a TomlToken instance.

public static implicit operator TomlToken(long value)

Parameters

value long

The long value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(sbyte)

Implicitly converts a sbyte value to a TomlToken instance.

public static implicit operator TomlToken(sbyte value)

Parameters

value sbyte

The sbyte value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.

implicit operator TomlToken(string)

Implicitly converts a string value to a TomlToken instance.

public static implicit operator TomlToken(string value)

Parameters

value string

The string value to convert.

Returns

TomlToken

A TomlPrimitiveValue representing value.