TomlSerializerOptions Class
Configures the behavior of TomlSerializer operations.
public sealed class TomlSerializerOptions : IEquatable<TomlSerializerOptions>- Implements
Constructors
| Name | Description |
|---|---|
| TomlSerializerOptions() |
TomlSerializerOptions()
TomlSerializerOptions.cspublic TomlSerializerOptions()No documentation is available.
Properties
| Name | Description |
|---|---|
| Converters | Gets the custom converters. |
| Default | Gets a default options instance. |
| DefaultIgnoreCondition | Gets or sets the default ignore condition for null/default values. |
| DictionaryKeyPolicy | Gets or sets the policy used to convert dictionary keys during serialization. |
| DottedKeyHandling | Gets or sets how member names and dictionary keys containing '.' are written. Reading is not affected. |
| DuplicateKeyHandling | Gets or sets behavior when duplicate keys are encountered while reading. |
| IgnoreReadOnlyFields | Gets or sets a value indicating whether read-only fields are ignored during serialization. |
| IgnoreReadOnlyProperties | Gets or sets a value indicating whether read-only properties are ignored during serialization. |
| IncludeFields | Gets or sets a value indicating whether public fields are included during serialization and deserialization. |
| IndentSize | Gets or sets the number of spaces to use when TomlSerializerOptions.WriteIndented is enabled. |
| InlineTablePolicy | Gets or sets inline table emission policy. |
| MappingOrder | Gets or sets member ordering behavior for emitted tables. The default, TomlMappingOrderPolicy.OrderThenDeclaration, honors TomlPropertyOrderAttribute. |
| MaxDepth | Gets or sets the maximum allowed nesting depth for TOML tables and arrays during serialization and deserialization. |
| MaxInputLength | Gets or sets the maximum length of the TOML input that TomlSerializer reads. |
| MetadataStore | Gets or sets an optional metadata store used to capture or apply TOML trivia/comment metadata. |
| NewLine | Gets or sets the newline kind used by the writer. |
| PolymorphismOptions | Gets polymorphism options. |
| PreferredObjectCreationHandling | Gets or sets the preferred object creation handling for properties and fields during deserialization. |
| PropertyNameCaseInsensitive | Gets or sets a value indicating whether property name matching is case-insensitive. |
| PropertyNamingPolicy | Gets or sets the policy used to convert CLR property names. |
| RespectNullableAnnotations | Gets or sets a value indicating whether nullable annotations are enforced during serialization and deserialization. |
| RespectRequiredConstructorParameters | Gets or sets a value indicating whether required constructor parameters must be present during deserialization. |
| RootValueHandling | Gets or sets behavior for scalar/array roots that do not naturally map to a TOML document. |
| RootValueKeyName | Gets the root key name used when TomlSerializerOptions.RootValueHandling is TomlRootValueHandling.WrapInRootKey. |
| SourceName | Gets or sets an optional name for the TOML source. |
| StringStylePreferences | Gets string style preferences for serialization. |
| TableArrayStyle | Gets or sets array-of-table emission style. |
| TypeInfoResolver | Gets or sets a metadata resolver used to retrieve TomlTypeInfo instances. |
| UnmappedMemberHandling | Gets or sets how unmapped TOML keys are handled during object deserialization. |
| WriteIndented | Gets or sets a value indicating whether nested tables are indented. |
Converters
TomlSerializerOptions.csGets the custom converters.
public IReadOnlyList<TomlConverter> Converters { get; init; }Property value
Exceptions
ArgumentNullException- Value is
null. ArgumentException- A converter entry is
null.
Remarks
Converters are evaluated in order and take precedence over built-in converters.
Default
TomlSerializerOptions.csDefaultIgnoreCondition
TomlSerializerOptions.csGets or sets the default ignore condition for null/default values.
public TomlIgnoreCondition DefaultIgnoreCondition { get; init; }Property value
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.csGets or sets the policy used to convert dictionary keys during serialization.
public TomlNamingPolicy? DictionaryKeyPolicy { get; init; }Property value
DottedKeyHandling
TomlSerializerOptions.csGets or sets how member names and dictionary keys containing '.' are written. Reading is not affected.
public TomlDottedKeyHandling DottedKeyHandling { get; init; }DuplicateKeyHandling
TomlSerializerOptions.csGets or sets behavior when duplicate keys are encountered while reading.
public TomlDuplicateKeyHandling DuplicateKeyHandling { get; init; }IgnoreReadOnlyFields
TomlSerializerOptions.csIgnoreReadOnlyProperties
TomlSerializerOptions.csIncludeFields
TomlSerializerOptions.csGets or sets a value indicating whether public fields are included during serialization and deserialization.
public bool IncludeFields { get; init; }IndentSize
TomlSerializerOptions.csGets or sets the number of spaces to use when TomlSerializerOptions.WriteIndented is enabled.
public int IndentSize { get; init; }InlineTablePolicy
TomlSerializerOptions.csGets or sets inline table emission policy.
public TomlInlineTablePolicy InlineTablePolicy { get; init; }MappingOrder
TomlSerializerOptions.csGets or sets member ordering behavior for emitted tables. The default, TomlMappingOrderPolicy.OrderThenDeclaration, honors TomlPropertyOrderAttribute.
public TomlMappingOrderPolicy MappingOrder { get; init; }MaxDepth
TomlSerializerOptions.csGets or sets the maximum allowed nesting depth for TOML tables and arrays during serialization and deserialization.
public int MaxDepth { get; init; }Property value
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.
MaxInputLength
TomlSerializerOptions.csGets or sets the maximum length of the TOML input that TomlSerializer reads.
public int MaxInputLength { get; init; }Property value
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.
MetadataStore
TomlSerializerOptions.csGets or sets an optional metadata store used to capture or apply TOML trivia/comment metadata.
public ITomlMetadataStore? MetadataStore { get; init; }Property value
NewLine
TomlSerializerOptions.csGets or sets the newline kind used by the writer.
public TomlNewLineKind NewLine { get; init; }PolymorphismOptions
TomlSerializerOptions.csGets polymorphism options.
public TomlPolymorphismOptions PolymorphismOptions { get; init; }Property value
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.csGets or sets the preferred object creation handling for properties and fields during deserialization.
public TomlObjectCreationHandling PreferredObjectCreationHandling { get; init; }Property value
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.csPropertyNamingPolicy
TomlSerializerOptions.csGets or sets the policy used to convert CLR property names.
public TomlNamingPolicy? PropertyNamingPolicy { get; init; }Property value
RespectNullableAnnotations
TomlSerializerOptions.csGets or sets a value indicating whether nullable annotations are enforced during serialization and deserialization.
public bool RespectNullableAnnotations { get; init; }Property value
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.csGets or sets a value indicating whether required constructor parameters must be present during deserialization.
public bool RespectRequiredConstructorParameters { get; init; }Property value
Remarks
When false, a missing constructor parameter without a default value receives the default value of its type.
RootValueHandling
TomlSerializerOptions.csGets or sets behavior for scalar/array roots that do not naturally map to a TOML document.
public TomlRootValueHandling RootValueHandling { get; init; }RootValueKeyName
TomlSerializerOptions.csGets the root key name used when TomlSerializerOptions.RootValueHandling is TomlRootValueHandling.WrapInRootKey.
public string RootValueKeyName { get; init; }Property value
Exceptions
ArgumentNullException- Value is
null. ArgumentException- Value is not a valid key name.
SourceName
TomlSerializerOptions.csGets or sets an optional name for the TOML source.
public string? SourceName { get; init; }Property value
Remarks
This value is used to annotate TomlException messages with a source name (for example, a file path) when reporting errors.
StringStylePreferences
TomlSerializerOptions.csGets string style preferences for serialization.
public TomlStringStylePreferences StringStylePreferences { get; init; }TableArrayStyle
TomlSerializerOptions.csGets or sets array-of-table emission style.
public TomlTableArrayStyle TableArrayStyle { get; init; }TypeInfoResolver
TomlSerializerOptions.csGets or sets a metadata resolver used to retrieve TomlTypeInfo instances.
public ITomlTypeInfoResolver? TypeInfoResolver { get; init; }Property value
UnmappedMemberHandling
TomlSerializerOptions.csGets or sets how unmapped TOML keys are handled during object deserialization.
public TomlUnmappedMemberHandling UnmappedMemberHandling { get; init; }Property value
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.
WriteIndented
TomlSerializerOptions.csGets or sets a value indicating whether nested tables are indented.
public bool WriteIndented { get; init; }Property value
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
| Name | Description |
|---|---|
| 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)No documentation is available.
Equals(object?)
GetHashCode()
GetTypeInfo<T>()
TomlSerializerOptions.csGets 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()
TryGetTypeInfo<T>(TomlTypeInfo<T>?)
TomlSerializerOptions.csAttempts 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
typeInfoTomlTypeInfo<T>?- The metadata resolved for
T, when available.
Returns
bool true when metadata is available for T; otherwise false.
Operators
| Name | Description |
|---|---|
| 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.