Class TomlToken
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
tokenTypeTomlTokenType
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
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
indexintThe 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
keystringThe 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
Tokens
Gets the enumerator that enumerates child TomlToken instances belonging to the current token.
public IEnumerable<TomlToken> Tokens { get; }
Property Value
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
otherTomlTokenThe 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
GetEnumerator()
public IEnumerator<TomlToken> GetEnumerator()
Returns
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?)
public static explicit operator bool?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid bool value.
explicit operator byte?(TomlToken?)
public static explicit operator byte?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid byte value.
explicit operator char?(TomlToken?)
public static explicit operator char?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid char value.
explicit operator DateTime?(TomlToken?)
public static explicit operator DateTime?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid DateTime value.
explicit operator decimal?(TomlToken?)
public static explicit operator decimal?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid decimal value.
explicit operator double?(TomlToken?)
public static explicit operator double?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid double value.
explicit operator Guid?(TomlToken?)
public static explicit operator Guid?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid Guid value.
explicit operator short?(TomlToken?)
public static explicit operator short?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid short value.
explicit operator int?(TomlToken?)
public static explicit operator int?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid integer value.
explicit operator long?(TomlToken?)
public static explicit operator long?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid long value.
explicit operator sbyte?(TomlToken?)
public static explicit operator sbyte?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid sbyte value.
explicit operator float?(TomlToken?)
public static explicit operator float?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid float value.
explicit operator ushort?(TomlToken?)
public static explicit operator ushort?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid ushort value.
explicit operator uint?(TomlToken?)
public static explicit operator uint?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid uint value.
explicit operator ulong?(TomlToken?)
public static explicit operator ulong?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokendoes not represent a valid ulong value.
explicit operator string?(TomlToken?)
public static explicit operator string?(TomlToken? tomlToken)
Parameters
Returns
Exceptions
- InvalidCastException
Thrown if
tomlTokencannot be represented as a valid TOML string.
implicit operator TomlToken(bool)
public static implicit operator TomlToken(bool value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(byte)
public static implicit operator TomlToken(byte value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(DateTime)
public static implicit operator TomlToken(DateTime value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(decimal)
public static implicit operator TomlToken(decimal value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(double)
public static implicit operator TomlToken(double value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(Guid)
public static implicit operator TomlToken(Guid value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(short)
public static implicit operator TomlToken(short value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(int)
public static implicit operator TomlToken(int value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(long)
public static implicit operator TomlToken(long value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(sbyte)
public static implicit operator TomlToken(sbyte value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.
implicit operator TomlToken(string)
public static implicit operator TomlToken(string value)
Parameters
Returns
- TomlToken
A TomlPrimitiveValue representing
value.