TomlSerializerOptions Class

Configures the behavior of TomlSerializer operations.

public sealed class TomlSerializerOptions : IEquatable<TomlSerializerOptions>
Implements

Constructors

NameDescription
TomlSerializerOptions()

TomlSerializerOptions()

TomlSerializerOptions.cs
public TomlSerializerOptions()

No documentation is available.

Properties

NameDescription
ConvertersGets the custom converters.
DefaultGets a default options instance.
DefaultIgnoreConditionGets or sets the default ignore condition for null/default values.
DictionaryKeyPolicyGets or sets the policy used to convert dictionary keys during serialization.
DottedKeyHandlingGets or sets how member names and dictionary keys containing '.' are written. Reading is not affected.
DuplicateKeyHandlingGets or sets behavior when duplicate keys are encountered while reading.
IgnoreReadOnlyFieldsGets or sets a value indicating whether read-only fields are ignored during serialization.
IgnoreReadOnlyPropertiesGets or sets a value indicating whether read-only properties are ignored during serialization.
IncludeFieldsGets or sets a value indicating whether public fields are included during serialization and deserialization.
IndentSizeGets or sets the number of spaces to use when TomlSerializerOptions.WriteIndented is enabled.
InlineTablePolicyGets or sets inline table emission policy.
MappingOrderGets or sets member ordering behavior for emitted tables. The default, TomlMappingOrderPolicy.OrderThenDeclaration, honors TomlPropertyOrderAttribute.
MaxDepthGets or sets the maximum allowed nesting depth for TOML tables and arrays during serialization and deserialization.
MaxInputLengthGets or sets the maximum length of the TOML input that TomlSerializer reads.
MetadataStoreGets or sets an optional metadata store used to capture or apply TOML trivia/comment metadata.
NewLineGets or sets the newline kind used by the writer.
PolymorphismOptionsGets polymorphism options.
PreferredObjectCreationHandlingGets or sets the preferred object creation handling for properties and fields during deserialization.
PropertyNameCaseInsensitiveGets or sets a value indicating whether property name matching is case-insensitive.
PropertyNamingPolicyGets or sets the policy used to convert CLR property names.
RespectNullableAnnotationsGets or sets a value indicating whether nullable annotations are enforced during serialization and deserialization.
RespectRequiredConstructorParametersGets or sets a value indicating whether required constructor parameters must be present during deserialization.
RootValueHandlingGets or sets behavior for scalar/array roots that do not naturally map to a TOML document.
RootValueKeyNameGets the root key name used when TomlSerializerOptions.RootValueHandling is TomlRootValueHandling.WrapInRootKey.
SourceNameGets or sets an optional name for the TOML source.
StringStylePreferencesGets string style preferences for serialization.
TableArrayStyleGets or sets array-of-table emission style.
TypeInfoResolverGets or sets a metadata resolver used to retrieve TomlTypeInfo instances.
UnmappedMemberHandlingGets or sets how unmapped TOML keys are handled during object deserialization.
WriteIndentedGets or sets a value indicating whether nested tables are indented.

Gets the custom converters.

public IReadOnlyList<TomlConverter> Converters { get; init; }

Property value

IReadOnlyList<TomlConverter>

Exceptions

ArgumentNullException
Value is null.
ArgumentException
A converter entry is null.

Remarks

Converters are evaluated in order and take precedence over built-in converters.

Gets a default options instance.

public static TomlSerializerOptions Default { get; }

Property value

TomlSerializerOptions

DefaultIgnoreCondition

TomlSerializerOptions.cs

Gets or sets the default ignore condition for null/default values.

public TomlIgnoreCondition DefaultIgnoreCondition { get; init; }

Property value

TomlIgnoreCondition

Exceptions

ArgumentOutOfRangeException
Value is another TomlIgnoreCondition.

Remarks

The default is TomlIgnoreCondition.WhenWritingNull, because TOML has no representation for null. Like System.Text.Json, only TomlIgnoreCondition.Never, TomlIgnoreCondition.WhenWritingNull, and TomlIgnoreCondition.WhenWritingDefault are allowed; use TomlIgnoreAttribute to ignore a member always or in one direction.

DictionaryKeyPolicy

TomlSerializerOptions.cs

Gets or sets the policy used to convert dictionary keys during serialization.

public TomlNamingPolicy? DictionaryKeyPolicy { get; init; }

Property value

TomlNamingPolicy?

DottedKeyHandling

TomlSerializerOptions.cs

Gets or sets how member names and dictionary keys containing '.' are written. Reading is not affected.

public TomlDottedKeyHandling DottedKeyHandling { get; init; }

Property value

TomlDottedKeyHandling

Exceptions

ArgumentOutOfRangeException
Value is not a defined TomlDottedKeyHandling.

DuplicateKeyHandling

TomlSerializerOptions.cs

Gets or sets behavior when duplicate keys are encountered while reading.

public TomlDuplicateKeyHandling DuplicateKeyHandling { get; init; }

IgnoreReadOnlyFields

TomlSerializerOptions.cs

Gets or sets a value indicating whether read-only fields are ignored during serialization.

public bool IgnoreReadOnlyFields { get; init; }

Property value

bool

IgnoreReadOnlyProperties

TomlSerializerOptions.cs

Gets or sets a value indicating whether read-only properties are ignored during serialization.

public bool IgnoreReadOnlyProperties { get; init; }

Property value

bool

Remarks

A property with an init accessor is not read-only.

Gets or sets a value indicating whether public fields are included during serialization and deserialization.

public bool IncludeFields { get; init; }

Property value

bool

Remarks

Fields annotated with TomlIncludeAttribute are always included.

Gets or sets the number of spaces to use when TomlSerializerOptions.WriteIndented is enabled.

public int IndentSize { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
Value is less than 1.

InlineTablePolicy

TomlSerializerOptions.cs

Gets or sets inline table emission policy.

public TomlInlineTablePolicy InlineTablePolicy { get; init; }

Property value

TomlInlineTablePolicy

Exceptions

ArgumentOutOfRangeException
Value is not a defined TomlInlineTablePolicy.

Gets or sets member ordering behavior for emitted tables. The default, TomlMappingOrderPolicy.OrderThenDeclaration, honors TomlPropertyOrderAttribute.

public TomlMappingOrderPolicy MappingOrder { get; init; }

Property value

TomlMappingOrderPolicy

Exceptions

ArgumentOutOfRangeException
Value is not a defined TomlMappingOrderPolicy.

Gets or sets the maximum allowed nesting depth for TOML tables and arrays during serialization and deserialization.

public int MaxDepth { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
Value is less than 0.

Remarks

A value of 0 uses the default limit of 64. There is no upper limit: a document nested deeper than the stack of the current thread allows throws a TomlException instead of overflowing the stack.

Gets or sets the maximum length of the TOML input that TomlSerializer reads.

public int MaxInputLength { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
Value is less than 0.

Remarks

The length is a number of characters for a String or a TextReader, and a number of bytes for a Stream, which is read no further than the limit. Longer input throws a TomlException. A value of 0, the default, means no limit.

Gets or sets an optional metadata store used to capture or apply TOML trivia/comment metadata.

public ITomlMetadataStore? MetadataStore { get; init; }

Property value

ITomlMetadataStore?

Gets or sets the newline kind used by the writer.

public TomlNewLineKind NewLine { get; init; }

Property value

TomlNewLineKind

Exceptions

ArgumentOutOfRangeException
Value is not a defined TomlNewLineKind.

PolymorphismOptions

TomlSerializerOptions.cs

Gets polymorphism options.

public TomlPolymorphismOptions PolymorphismOptions { get; init; }

Property value

TomlPolymorphismOptions

Exceptions

ArgumentNullException
Value is null.

Remarks

TomlPolymorphismOptions is immutable: its TomlPolymorphismOptions.DerivedTypeMappings are copied when assigned, so options that are already in use cannot change.

PreferredObjectCreationHandling

TomlSerializerOptions.cs

Gets or sets the preferred object creation handling for properties and fields during deserialization.

public TomlObjectCreationHandling PreferredObjectCreationHandling { get; init; }

Property value

TomlObjectCreationHandling

Exceptions

ArgumentOutOfRangeException
Value is not a defined object creation handling.

Remarks

A member-level or type-level object creation handling attribute overrides this setting. The default behavior is TomlObjectCreationHandling.Replace.

PropertyNameCaseInsensitive

TomlSerializerOptions.cs

Gets or sets a value indicating whether property name matching is case-insensitive.

public bool PropertyNameCaseInsensitive { get; init; }

Property value

bool

PropertyNamingPolicy

TomlSerializerOptions.cs

Gets or sets the policy used to convert CLR property names.

public TomlNamingPolicy? PropertyNamingPolicy { get; init; }

Property value

TomlNamingPolicy?

RespectNullableAnnotations

TomlSerializerOptions.cs

Gets or sets a value indicating whether nullable annotations are enforced during serialization and deserialization.

public bool RespectNullableAnnotations { get; init; }

Property value

bool

Remarks

When true, a null value in a member or constructor parameter declared as a non-nullable reference type throws a TomlException. The check applies before TomlSerializerOptions.DefaultIgnoreCondition.

RespectRequiredConstructorParameters

TomlSerializerOptions.cs

Gets or sets a value indicating whether required constructor parameters must be present during deserialization.

public bool RespectRequiredConstructorParameters { get; init; }

Property value

bool

Remarks

When false, a missing constructor parameter without a default value receives the default value of its type.

RootValueHandling

TomlSerializerOptions.cs

Gets or sets behavior for scalar/array roots that do not naturally map to a TOML document.

public TomlRootValueHandling RootValueHandling { get; init; }

Property value

TomlRootValueHandling

Exceptions

ArgumentOutOfRangeException
Value is not a defined TomlRootValueHandling.

RootValueKeyName

TomlSerializerOptions.cs
public string RootValueKeyName { get; init; }

Property value

string

Exceptions

ArgumentNullException
Value is null.
ArgumentException
Value is not a valid key name.

Gets or sets an optional name for the TOML source.

public string? SourceName { get; init; }

Property value

string?

Remarks

This value is used to annotate TomlException messages with a source name (for example, a file path) when reporting errors.

StringStylePreferences

TomlSerializerOptions.cs

Gets string style preferences for serialization.

public TomlStringStylePreferences StringStylePreferences { get; init; }

Property value

TomlStringStylePreferences

Exceptions

ArgumentNullException
Value is null.

Gets or sets array-of-table emission style.

public TomlTableArrayStyle TableArrayStyle { get; init; }

Property value

TomlTableArrayStyle

Exceptions

ArgumentOutOfRangeException
Value is not a defined TomlTableArrayStyle.

TypeInfoResolver

TomlSerializerOptions.cs

Gets or sets a metadata resolver used to retrieve TomlTypeInfo instances.

public ITomlTypeInfoResolver? TypeInfoResolver { get; init; }

UnmappedMemberHandling

TomlSerializerOptions.cs

Gets or sets how unmapped TOML keys are handled during object deserialization.

public TomlUnmappedMemberHandling UnmappedMemberHandling { get; init; }

Property value

TomlUnmappedMemberHandling

Exceptions

ArgumentOutOfRangeException
Value is not a defined TomlUnmappedMemberHandling.

Remarks

A type-level TomlUnmappedMemberHandlingAttribute overrides this setting. Extension data members still capture unmapped keys when present.

Gets or sets a value indicating whether nested tables are indented.

public bool WriteIndented { get; init; }

Property value

bool

Remarks

The header of a table and its key/value pairs are indented by TomlSerializerOptions.IndentSize spaces for each table they are nested in: [a] is not indented, and [a.b] is indented once. The default is false.

Methods

NameDescription
Equals(TomlSerializerOptions?)
Equals(object?)
GetHashCode()
GetTypeInfo<T>()Gets the TomlTypeInfo<T> contract metadata resolved by this options instance.
ToString()
TryGetTypeInfo<T>(TomlTypeInfo<T>?)Attempts to get the TomlTypeInfo<T> contract metadata resolved by this options instance.

Equals overloads

Equals(TomlSerializerOptions?)

public bool Equals(TomlSerializerOptions? other)
Parameters
other TomlSerializerOptions?
Returns

bool

No documentation is available.

Equals(object?)

public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetHashCode()

public override int GetHashCode()

Returns

int

No documentation is available.

GetTypeInfo<T>()

TomlSerializerOptions.cs

Gets the TomlTypeInfo<T> contract metadata resolved by this options instance.

[RequiresDynamicCode("Reflection-based TOML serialization is not compatible with trimming/NativeAOT. Use a source-generated TomlSerializerContext or pass a TomlTypeInfo instance.")]
[RequiresUnreferencedCode("Reflection-based TOML serialization is not compatible with trimming/NativeAOT. Use a source-generated TomlSerializerContext or pass a TomlTypeInfo instance.")]
public TomlTypeInfo<T> GetTypeInfo<T>()

Type parameters

T
The type to resolve metadata for.

Returns

TomlTypeInfo<T> The metadata resolved for T.

Exceptions

TomlException
No metadata is available for T.

ToString()

public override string ToString()

Returns

string

No documentation is available.

TryGetTypeInfo<T>(TomlTypeInfo<T>?)

TomlSerializerOptions.cs

Attempts to get the TomlTypeInfo<T> contract metadata resolved by this options instance.

[RequiresDynamicCode("Reflection-based TOML serialization is not compatible with trimming/NativeAOT. Use a source-generated TomlSerializerContext or pass a TomlTypeInfo instance.")]
[RequiresUnreferencedCode("Reflection-based TOML serialization is not compatible with trimming/NativeAOT. Use a source-generated TomlSerializerContext or pass a TomlTypeInfo instance.")]
public bool TryGetTypeInfo<T>(out TomlTypeInfo<T>? typeInfo)

Type parameters

T
The type to resolve metadata for.

Parameters

typeInfo TomlTypeInfo<T>?
The metadata resolved for T, when available.

Returns

bool true when metadata is available for T; otherwise false.

Operators

NameDescription
operator ==(TomlSerializerOptions?, TomlSerializerOptions?)
operator !=(TomlSerializerOptions?, TomlSerializerOptions?)

operator ==(TomlSerializerOptions?, TomlSerializerOptions?)

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

No documentation is available.

operator !=(TomlSerializerOptions?, TomlSerializerOptions?)

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

No documentation is available.