TomlValue Class

A mutable TOML value: a string, a number, a boolean, or a date or a time.

public abstract class TomlValue : TomlNode, IEquatable<TomlValue>

Remarks

A value keeps the .NET type it is created from, such as Int32 or Single, and TomlValue.GetValue converts it to another compatible type. Values are equal when they are the same TOML value.

Inheritance
TomlNode TomlValue
Implements

Properties

NameDescription
ValueGets the value as it is stored.

Value

Gets the value as it is stored.

public abstract object Value { get; }

Property value

object

Methods

NameDescription
Create(TomlDateTime)Creates a date or time value.
Create(bool)Creates a boolean value.
Create(DateOnly)Creates a local date value.
Create(DateTime)Creates a date-time value: an offset date-time for a UTC or local DateTime, and a local date-time otherwise.
Create(DateTimeOffset)Creates an offset date-time value.
Create(decimal)Creates a float value, written with all the digits of the Decimal.
Create(double)Creates a float value.
Create(int)Creates an integer value.
Create(long)Creates an integer value.
Create(float)Creates a float value, written with the shortest text that reads back as the same Single.
Create(string)Creates a string value.
Create(TimeOnly)Creates a local time value.
Create<T>(T)Creates a value of any type, which TomlSerializer writes with its converter, such as a Guid or an enum.
Equals(TomlValue?)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Determines whether the specified object is equal to the current object.
GetHashCode()Serves as the default hash function.
GetValue<T>()Gets the value converted to T.
GetValueKind()Gets the kind of the value.
ToString()Gets the text of a string value, or the TOML text of the other values.
TryGetValue<T>(T)Gets the value converted to T.
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.

Create overloads

Create(TomlDateTime)

TomlValue.cs

Creates a date or time value.

public static TomlValue Create(TomlDateTime value)
Parameters
value TomlDateTime
Returns

TomlValue

Create(bool)

TomlValue.cs

Creates a boolean value.

public static TomlValue Create(bool value)
Parameters
value bool
Returns

TomlValue

Create(DateOnly)

TomlValue.cs

Creates a local date value.

public static TomlValue Create(DateOnly value)
Parameters
value DateOnly
Returns

TomlValue

Create(DateTime)

TomlValue.cs

Creates a date-time value: an offset date-time for a UTC or local DateTime, and a local date-time otherwise.

public static TomlValue Create(DateTime value)
Parameters
value DateTime
Returns

TomlValue

Create(DateTimeOffset)

TomlValue.cs

Creates an offset date-time value.

public static TomlValue Create(DateTimeOffset value)
Parameters
value DateTimeOffset
Returns

TomlValue

Create(decimal)

TomlValue.cs

Creates a float value, written with all the digits of the Decimal.

public static TomlValue Create(decimal value)
Parameters
value decimal
Returns

TomlValue

Create(double)

TomlValue.cs

Creates a float value.

public static TomlValue Create(double value)
Parameters
value double
Returns

TomlValue

Create(int)

TomlValue.cs

Creates an integer value.

public static TomlValue Create(int value)
Parameters
value int
Returns

TomlValue

Create(long)

TomlValue.cs

Creates an integer value.

public static TomlValue Create(long value)
Parameters
value long
Returns

TomlValue

Create(float)

TomlValue.cs

Creates a float value, written with the shortest text that reads back as the same Single.

public static TomlValue Create(float value)
Parameters
value float
Returns

TomlValue

Create(string)

TomlValue.cs

Creates a string value.

public static TomlValue Create(string value)
Parameters
value string
Returns

TomlValue

Create(TimeOnly)

TomlValue.cs

Creates a local time value.

public static TomlValue Create(TimeOnly value)
Parameters
value TimeOnly
Returns

TomlValue

Create<T>(T)

TomlValue.cs

Creates a value of any type, which TomlSerializer writes with its converter, such as a Guid or an enum.

public static TomlValue Create<T>(T value) where T : notnull
Type parameters
T
Parameters
value T
Returns

TomlValue

Equals overloads

Equals(TomlValue?)

TomlValue.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(TomlValue? other)
Parameters
other TomlValue?
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

TomlValue.cs

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current object.
Returns

bool true if the specified object is equal to the current object; otherwise, false.

GetHashCode()

TomlValue.cs

Serves as the default hash function.

public override int GetHashCode()

Returns

int A hash code for the current object.

GetValue<T>()

TomlValue.cs

Gets the value converted to T.

public new T GetValue<T>()

Type parameters

T

Returns

T

Exceptions

InvalidOperationException
The value cannot be converted to T.

GetValueKind()

TomlValue.cs

Gets the kind of the value.

public override TomlValueKind GetValueKind()

ToString()

TomlValue.cs

Gets the text of a string value, or the TOML text of the other values.

public override string ToString()

Returns

string

TryGetValue<T>(T)

TomlValue.cs

Gets the value converted to T.

public bool TryGetValue<T>(out T value)

Type parameters

T

Parameters

value T

Returns

bool

WriteTo(Utf8TomlWriter)

TomlValue.cs

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 override void WriteTo(Utf8TomlWriter writer)

Parameters

writer Utf8TomlWriter
The writer.

Operators

NameDescription
operator ==(TomlValue?, TomlValue?)Compares two values.
operator !=(TomlValue?, TomlValue?)Compares two values.

operator ==(TomlValue?, TomlValue?)

TomlValue.cs

Compares two values.

public static bool operator ==(TomlValue? left, TomlValue? right)

Parameters

left TomlValue?
right TomlValue?

Returns

bool

operator !=(TomlValue?, TomlValue?)

TomlValue.cs

Compares two values.

public static bool operator !=(TomlValue? left, TomlValue? right)

Parameters

left TomlValue?
right TomlValue?

Returns

bool