TomlSerializerContext Class

Base type for source-generated TOML serializer contexts.

public abstract class TomlSerializerContext : ITomlTypeInfoResolver
Implements

Constructors

NameDescription
TomlSerializerContext()Initializes a new instance of the TomlSerializerContext class.
TomlSerializerContext(TomlSerializerOptions)Initializes a new instance of the TomlSerializerContext class.

TomlSerializerContext overloads

TomlSerializerContext()

TomlSerializerContext.cs

Initializes a new instance of the TomlSerializerContext class.

protected TomlSerializerContext()

TomlSerializerContext(TomlSerializerOptions)

TomlSerializerContext.cs

Initializes a new instance of the TomlSerializerContext class.

protected TomlSerializerContext(TomlSerializerOptions options)
Parameters
options TomlSerializerOptions
The options used by this context.

Properties

NameDescription
OptionsGets the options instance associated with this context.

Gets the options instance associated with this context.

public TomlSerializerOptions Options { get; }

Property value

TomlSerializerOptions

Methods

NameDescription
AddCollectionToSingleOrArrayCollection<T>(object, IEnumerable<T>)Adds incoming values to an existing collection for source-generated TomlSingleOrArrayAttribute handling.
AddSingleElementToSingleOrArrayCollection<T>(object, T)Adds a single element to an existing collection for source-generated TomlSingleOrArrayAttribute handling.
ApplyPropertyMetadata(TomlWriter, string, TomlPropertyMetadata)Applies formatting metadata for a TOML property currently being written by source-generated metadata.
AttachPropertiesMetadata<T>(TomlWriter, T)Writes the metadata stored for an instance, such as its comments, when TomlSerializerOptions.MetadataStore is set.
BeginPropertiesMetadata<T>(TomlReader)Starts recording how the properties of the table at the current position are written, when TomlSerializerOptions.MetadataStore is set.
CanPopulateSingleOrArrayCollection<T>(object)Determines whether an existing collection can be populated for source-generated TomlSingleOrArrayAttribute handling.
CaptureValue(TomlReader)Reads the current value into a buffer and moves the reader past it, so that the value can be read later, such as into a get-only member of an object that is created once its other members are read.
CreateAttributeConverterTypeInfo<T>(TomlSerializerOptions, TomlConverter)Creates metadata for a converter declared with TomlConverterAttribute.
CreateConfigurationException(string)Creates an exception for an error of the model rather than of the TOML input, such as a type without a usable constructor. TomlSerializer.TryDeserialize throws it instead of returning false.
CreateConfigurationException(string, Exception?)Creates an exception for an error of the model rather than of the TOML input, such as a converter whose constructor throws. TomlSerializer.TryDeserialize throws it instead of returning false.
CreateConverterTypeInfo<T>(TomlSerializerOptions, TomlConverter<T>)Creates metadata for a type handled by a source-generation converter option.
CreateNullableStringEnumTypeInfo<TEnum>(TomlSerializerOptions)Creates metadata for a nullable enum type that writes values as strings.
CreateSingleElementArray<T>(T)Creates an array with a single element for source-generated TomlSingleOrArrayAttribute handling.
CreateSingleElementCollection<TCollection, TElement>(TElement)Creates a mutable collection with a single element for source-generated TomlSingleOrArrayAttribute handling.
CreateSingleElementHashSet<T>(T)Creates a hash set with a single element for source-generated TomlSingleOrArrayAttribute handling.
CreateSingleElementImmutableArray<T>(T)Creates an immutable array with a single element for source-generated TomlSingleOrArrayAttribute handling.
CreateSingleElementImmutableHashSet<T>(T)Creates an immutable hash set with a single element for source-generated TomlSingleOrArrayAttribute handling.
CreateSingleElementImmutableList<T>(T)Creates an immutable list with a single element for source-generated TomlSingleOrArrayAttribute handling.
CreateSingleElementList<T>(T)Creates a list with a single element for source-generated TomlSingleOrArrayAttribute handling.
CreateSourceGeneratedArrayTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for a single-dimensional array type using source-generated resolution for nested elements.
CreateSourceGeneratedConcreteDictionaryTypeInfo<TDictionary, TValue>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for a concrete dictionary type with string keys, such as SortedDictionary<TKey, TValue>, using source-generated resolution for nested values.
CreateSourceGeneratedDictionaryTypeInfo<TDictionary, TValue>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for a dictionary-like type with string keys using source-generated resolution for nested values.
CreateSourceGeneratedHashSetBackedEnumerableTypeInfo<TEnumerable, TElement>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for a set-like interface type backed by HashSet<T> using source-generated resolution for nested elements.
CreateSourceGeneratedHashSetTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for a HashSet<T> using source-generated resolution for nested elements.
CreateSourceGeneratedImmutableArrayTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for ImmutableArray<T> using source-generated resolution for nested elements.
CreateSourceGeneratedImmutableHashSetTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for ImmutableHashSet<T> using source-generated resolution for nested elements.
CreateSourceGeneratedImmutableListTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for ImmutableList<T> using source-generated resolution for nested elements.
CreateSourceGeneratedListBackedEnumerableTypeInfo<TEnumerable, TElement>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for an enumerable interface type backed by List<T> using source-generated resolution for nested elements.
CreateSourceGeneratedListTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for a List<T> using source-generated resolution for nested elements.
CreateSourceGeneratedMutableCollectionTypeInfo<TCollection, TElement>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for a mutable collection type using source-generated resolution for nested elements.
CreateSourceGeneratedNullableTypeInfo<T>(TomlSerializerContext, TomlSerializerOptions?)Creates metadata for a nullable value type (Nullable<T>) using source-generated resolution for the underlying value type.
CreateStringEnumTypeInfo<TEnum>(TomlSerializerOptions)Creates metadata for an enum type that writes values as strings.
EndPropertiesMetadata<T>(TomlReader, TomlPropertiesMetadata?, T)Stores the metadata recorded since TomlSerializerContext.BeginPropertiesMetadata for an instance.
GetBuiltInTypeInfo<T>(TomlSerializerOptions)Resolves built-in type metadata for a known scalar/container type.
GetDeserializationDiagnosticCount(TomlReader)Gets the number of recoverable deserialization diagnostics recorded for the reader, to pass to TomlSerializerContext.ThrowIfDeserializationDiagnostics at the end of a table.
GetTypeInfo(Type, TomlSerializerOptions)Gets type metadata for a CLR type.
ReportDeserializationError(TomlReader, TomlSourceSpan?, string)Reports an error found after a table was read, such as a missing required key. It is recorded with the other deserialization diagnostics, and TomlSerializerContext.ThrowIfDeserializationDiagnostics throws once every error of the table is found. It is thrown directly when the diagnostics cannot be recorded.
ReportDuplicateKey(TomlReader, string)Reports a key that maps to a member that was already read, such as Name and name when property names are case-insensitive. The error is recorded with the other deserialization diagnostics, and the value is skipped. It is thrown directly when the diagnostics cannot be recorded.
ResolveRuntimeConverterTypeInfo(TomlSerializerOptions, Type, Type[]?)Resolves converter-based metadata for a runtime converter registered on options.
ThrowIfDeserializationDiagnostics(TomlReader, int, TomlSourceSpan?)Throws a TomlException when recoverable deserialization diagnostics were recorded since TomlSerializerContext.GetDeserializationDiagnosticCount returned diagnosticCount. The table that contains the value continues with its next value, so the errors of the rest of the document are reported as well.
TryAddDeserializationDiagnostic(TomlReader, TomlTokenType, TomlSourceSpan?, TomlException)Records a recoverable deserialization diagnostic and skips the current TOML value when the reader is still positioned on the same token that failed.
WritePropertyName(TomlWriter, string, TomlDottedKeyHandling?)Writes a TOML property name using an optional dotted-key handling override.

AddCollectionToSingleOrArrayCollection<T>(object, IEnumerable<T>)

TomlSerializerContext.cs

Adds incoming values to an existing collection for source-generated TomlSingleOrArrayAttribute handling.

protected static object AddCollectionToSingleOrArrayCollection<T>(object existingValue, IEnumerable<T> incomingCollection)

Type parameters

T
The collection element type.

Parameters

existingValue object
The existing collection instance.
incomingCollection IEnumerable<T>
The values to add.

Returns

object The populated collection instance.

AddSingleElementToSingleOrArrayCollection<T>(object, T)

TomlSerializerContext.cs

Adds a single element to an existing collection for source-generated TomlSingleOrArrayAttribute handling.

protected static object AddSingleElementToSingleOrArrayCollection<T>(object existingValue, T element)

Type parameters

T
The collection element type.

Parameters

existingValue object
The existing collection instance.
element T
The element to add.

Returns

object The populated collection instance.

ApplyPropertyMetadata(TomlWriter, string, TomlPropertyMetadata)

TomlSerializerContext.cs

Applies formatting metadata for a TOML property currently being written by source-generated metadata.

protected static void ApplyPropertyMetadata(TomlWriter writer, string name, TomlPropertyMetadata metadata)

Parameters

writer TomlWriter
The TOML writer.
name string
The property name.
metadata TomlPropertyMetadata
The metadata to merge.

AttachPropertiesMetadata<T>(TomlWriter, T)

TomlSerializerContext.cs

Writes the metadata stored for an instance, such as its comments, when TomlSerializerOptions.MetadataStore is set.

protected static void AttachPropertiesMetadata<T>(TomlWriter writer, T value)

Type parameters

T
The type written as a table.

Parameters

writer TomlWriter
The writer, after the start of the table.
value T
The instance.

BeginPropertiesMetadata<T>(TomlReader)

TomlSerializerContext.cs

Starts recording how the properties of the table at the current position are written, when TomlSerializerOptions.MetadataStore is set.

protected static TomlPropertiesMetadata? BeginPropertiesMetadata<T>(TomlReader reader)

Type parameters

T
The type read from the table.

Parameters

reader TomlReader
The reader, positioned on TomlTokenType.StartTable.

Returns

TomlPropertiesMetadata? The metadata to pass to TomlSerializerContext.EndPropertiesMetadata, or null.

CanPopulateSingleOrArrayCollection<T>(object)

TomlSerializerContext.cs

Determines whether an existing collection can be populated for source-generated TomlSingleOrArrayAttribute handling.

protected static bool CanPopulateSingleOrArrayCollection<T>(object existingValue)

Type parameters

T
The collection element type.

Parameters

existingValue object
The existing collection instance.

Returns

bool true when the collection can be populated in place.

CaptureValue(TomlReader)

TomlSerializerContext.cs

Reads the current value into a buffer and moves the reader past it, so that the value can be read later, such as into a get-only member of an object that is created once its other members are read.

protected static TomlReader CaptureValue(TomlReader reader)

Parameters

reader TomlReader
The TOML reader, positioned on the first token of the value.

Returns

TomlReader A reader positioned on the first token of the captured value.

CreateAttributeConverterTypeInfo<T>(TomlSerializerOptions, TomlConverter)

TomlSerializerContext.cs

Creates metadata for a converter declared with TomlConverterAttribute.

protected static TomlTypeInfo<T> CreateAttributeConverterTypeInfo<T>(TomlSerializerOptions options, TomlConverter converter)

Type parameters

T
The type handled by the converter.

Parameters

options TomlSerializerOptions
The serializer options.
converter TomlConverter
The converter instance, which can be a TomlConverterFactory.

Returns

TomlTypeInfo<T> Converter-based TOML metadata.

Exceptions

TomlException
The converter cannot convert T.

CreateConfigurationException overloads

CreateConfigurationException(string)

TomlSerializerContext.cs

Creates an exception for an error of the model rather than of the TOML input, such as a type without a usable constructor. TomlSerializer.TryDeserialize throws it instead of returning false.

protected static TomlException CreateConfigurationException(string message)
Parameters
message string
The error message.
Returns

TomlException The exception to throw.

CreateConfigurationException(string, Exception?)

TomlSerializerContext.cs

Creates an exception for an error of the model rather than of the TOML input, such as a converter whose constructor throws. TomlSerializer.TryDeserialize throws it instead of returning false.

protected static TomlException CreateConfigurationException(string message, Exception? innerException)
Parameters
message string
The error message.
innerException Exception?
The exception that caused the error.
Returns

TomlException The exception to throw.

CreateConverterTypeInfo<T>(TomlSerializerOptions, TomlConverter<T>)

TomlSerializerContext.cs

Creates metadata for a type handled by a source-generation converter option.

protected static TomlTypeInfo<T> CreateConverterTypeInfo<T>(TomlSerializerOptions options, TomlConverter<T> converter)

Type parameters

T
The type handled by the converter.

Parameters

options TomlSerializerOptions
The serializer options.
converter TomlConverter<T>
The converter instance.

Returns

TomlTypeInfo<T> Converter-based TOML metadata.

CreateNullableStringEnumTypeInfo<TEnum>(TomlSerializerOptions)

TomlSerializerContext.cs

Creates metadata for a nullable enum type that writes values as strings.

protected static TomlTypeInfo<TEnum?> CreateNullableStringEnumTypeInfo<TEnum>(TomlSerializerOptions options) where TEnum : struct, Enum

Type parameters

TEnum
The enum type.

Parameters

options TomlSerializerOptions
The serializer options.

Returns

TomlTypeInfo<TEnum?> The nullable enum metadata.

CreateSingleElementArray<T>(T)

TomlSerializerContext.cs

Creates an array with a single element for source-generated TomlSingleOrArrayAttribute handling.

protected static T[] CreateSingleElementArray<T>(T element)

Type parameters

T
The collection element type.

Parameters

element T
The element to place in the collection.

Returns

T[] An array containing element.

CreateSingleElementCollection<TCollection, TElement>(TElement)

TomlSerializerContext.cs

Creates a mutable collection with a single element for source-generated TomlSingleOrArrayAttribute handling.

protected static TCollection CreateSingleElementCollection<TCollection, TElement>(TElement element) where TCollection : ICollection<TElement>, new()

Type parameters

TCollection
The collection type.
TElement
The collection element type.

Parameters

element TElement
The element to place in the collection.

Returns

TCollection A collection containing element.

CreateSingleElementHashSet<T>(T)

TomlSerializerContext.cs

Creates a hash set with a single element for source-generated TomlSingleOrArrayAttribute handling.

protected static HashSet<T> CreateSingleElementHashSet<T>(T element)

Type parameters

T
The collection element type.

Parameters

element T
The element to place in the collection.

Returns

HashSet<T> A hash set containing element.

CreateSingleElementImmutableArray<T>(T)

TomlSerializerContext.cs

Creates an immutable array with a single element for source-generated TomlSingleOrArrayAttribute handling.

protected static ImmutableArray<T> CreateSingleElementImmutableArray<T>(T element)

Type parameters

T
The collection element type.

Parameters

element T
The element to place in the collection.

Returns

ImmutableArray<T> An immutable array containing element.

CreateSingleElementImmutableHashSet<T>(T)

TomlSerializerContext.cs

Creates an immutable hash set with a single element for source-generated TomlSingleOrArrayAttribute handling.

protected static ImmutableHashSet<T> CreateSingleElementImmutableHashSet<T>(T element)

Type parameters

T
The collection element type.

Parameters

element T
The element to place in the collection.

Returns

ImmutableHashSet<T> An immutable hash set containing element.

CreateSingleElementImmutableList<T>(T)

TomlSerializerContext.cs

Creates an immutable list with a single element for source-generated TomlSingleOrArrayAttribute handling.

protected static ImmutableList<T> CreateSingleElementImmutableList<T>(T element)

Type parameters

T
The collection element type.

Parameters

element T
The element to place in the collection.

Returns

ImmutableList<T> An immutable list containing element.

CreateSingleElementList<T>(T)

TomlSerializerContext.cs

Creates a list with a single element for source-generated TomlSingleOrArrayAttribute handling.

protected static List<T> CreateSingleElementList<T>(T element)

Type parameters

T
The collection element type.

Parameters

element T
The element to place in the collection.

Returns

List<T> A list containing element.

CreateSourceGeneratedArrayTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for a single-dimensional array type using source-generated resolution for nested elements.

protected static TomlTypeInfo<TElement[]> CreateSourceGeneratedArrayTypeInfo<TElement>(TomlSerializerContext context, TomlSerializerOptions? options = null)

Type parameters

TElement

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<TElement[]>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedConcreteDictionaryTypeInfo<TDictionary, TValue>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for a concrete dictionary type with string keys, such as SortedDictionary<TKey, TValue>, using source-generated resolution for nested values.

protected static TomlTypeInfo<TDictionary> CreateSourceGeneratedConcreteDictionaryTypeInfo<TDictionary, TValue>(TomlSerializerContext context, TomlSerializerOptions? options = null) where TDictionary : IDictionary<string, TValue>, new()

Type parameters

TDictionary
TValue

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<TDictionary>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedDictionaryTypeInfo<TDictionary, TValue>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for a dictionary-like type with string keys using source-generated resolution for nested values.

protected static TomlTypeInfo<TDictionary> CreateSourceGeneratedDictionaryTypeInfo<TDictionary, TValue>(TomlSerializerContext context, TomlSerializerOptions? options = null) where TDictionary : IEnumerable<KeyValuePair<string, TValue>>

Type parameters

TDictionary
TValue

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<TDictionary>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedHashSetBackedEnumerableTypeInfo<TEnumerable, TElement>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for a set-like interface type backed by HashSet<T> using source-generated resolution for nested elements.

protected static TomlTypeInfo<TEnumerable> CreateSourceGeneratedHashSetBackedEnumerableTypeInfo<TEnumerable, TElement>(TomlSerializerContext context, TomlSerializerOptions? options = null) where TEnumerable : IEnumerable<TElement>

Type parameters

TEnumerable
TElement

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<TEnumerable>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedHashSetTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for a HashSet<T> using source-generated resolution for nested elements.

protected static TomlTypeInfo<HashSet<TElement>> CreateSourceGeneratedHashSetTypeInfo<TElement>(TomlSerializerContext context, TomlSerializerOptions? options = null)

Type parameters

TElement

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<HashSet<TElement>>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedImmutableArrayTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for ImmutableArray<T> using source-generated resolution for nested elements.

protected static TomlTypeInfo<ImmutableArray<TElement>> CreateSourceGeneratedImmutableArrayTypeInfo<TElement>(TomlSerializerContext context, TomlSerializerOptions? options = null)

Type parameters

TElement

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<ImmutableArray<TElement>>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedImmutableHashSetTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for ImmutableHashSet<T> using source-generated resolution for nested elements.

protected static TomlTypeInfo<ImmutableHashSet<TElement>> CreateSourceGeneratedImmutableHashSetTypeInfo<TElement>(TomlSerializerContext context, TomlSerializerOptions? options = null)

Type parameters

TElement

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<ImmutableHashSet<TElement>>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedImmutableListTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for ImmutableList<T> using source-generated resolution for nested elements.

protected static TomlTypeInfo<ImmutableList<TElement>> CreateSourceGeneratedImmutableListTypeInfo<TElement>(TomlSerializerContext context, TomlSerializerOptions? options = null)

Type parameters

TElement

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<ImmutableList<TElement>>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedListBackedEnumerableTypeInfo<TEnumerable, TElement>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for an enumerable interface type backed by List<T> using source-generated resolution for nested elements.

protected static TomlTypeInfo<TEnumerable> CreateSourceGeneratedListBackedEnumerableTypeInfo<TEnumerable, TElement>(TomlSerializerContext context, TomlSerializerOptions? options = null) where TEnumerable : IEnumerable<TElement>

Type parameters

TEnumerable
TElement

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<TEnumerable>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedListTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for a List<T> using source-generated resolution for nested elements.

protected static TomlTypeInfo<List<TElement>> CreateSourceGeneratedListTypeInfo<TElement>(TomlSerializerContext context, TomlSerializerOptions? options = null)

Type parameters

TElement

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<List<TElement>>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedMutableCollectionTypeInfo<TCollection, TElement>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for a mutable collection type using source-generated resolution for nested elements.

protected static TomlTypeInfo<TCollection> CreateSourceGeneratedMutableCollectionTypeInfo<TCollection, TElement>(TomlSerializerContext context, TomlSerializerOptions? options = null) where TCollection : ICollection<TElement>, new()

Type parameters

TCollection
TElement

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<TCollection>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateSourceGeneratedNullableTypeInfo<T>(TomlSerializerContext, TomlSerializerOptions?)

TomlSerializerContext.cs

Creates metadata for a nullable value type (Nullable<T>) using source-generated resolution for the underlying value type.

protected static TomlTypeInfo<T?> CreateSourceGeneratedNullableTypeInfo<T>(TomlSerializerContext context, TomlSerializerOptions? options = null) where T : struct

Type parameters

T

Parameters

context TomlSerializerContext
options TomlSerializerOptions?

Returns

TomlTypeInfo<T?>

Remarks

This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.

CreateStringEnumTypeInfo<TEnum>(TomlSerializerOptions)

TomlSerializerContext.cs

Creates metadata for an enum type that writes values as strings.

protected static TomlTypeInfo<TEnum> CreateStringEnumTypeInfo<TEnum>(TomlSerializerOptions options) where TEnum : struct, Enum

Type parameters

TEnum
The enum type.

Parameters

options TomlSerializerOptions
The serializer options.

Returns

TomlTypeInfo<TEnum> The enum metadata.

EndPropertiesMetadata<T>(TomlReader, TomlPropertiesMetadata?, T)

TomlSerializerContext.cs

Stores the metadata recorded since TomlSerializerContext.BeginPropertiesMetadata for an instance.

protected static void EndPropertiesMetadata<T>(TomlReader reader, TomlPropertiesMetadata? metadata, T value)

Type parameters

T
The type read from the table.

Parameters

reader TomlReader
The reader.
metadata TomlPropertiesMetadata?
The metadata returned by TomlSerializerContext.BeginPropertiesMetadata.
value T
The instance read from the table.

GetBuiltInTypeInfo<T>(TomlSerializerOptions)

TomlSerializerContext.cs

Resolves built-in type metadata for a known scalar/container type.

protected static TomlTypeInfo<T> GetBuiltInTypeInfo<T>(TomlSerializerOptions options)

Type parameters

T

Parameters

options TomlSerializerOptions

Returns

TomlTypeInfo<T>

Remarks

This method exists to support source-generated contexts without requiring generated code to reference internal resolver types.

GetDeserializationDiagnosticCount(TomlReader)

TomlSerializerContext.cs

Gets the number of recoverable deserialization diagnostics recorded for the reader, to pass to TomlSerializerContext.ThrowIfDeserializationDiagnostics at the end of a table.

protected static int GetDeserializationDiagnosticCount(TomlReader reader)

Parameters

reader TomlReader
The TOML reader.

Returns

int The number of diagnostics.

GetTypeInfo(Type, TomlSerializerOptions)

Gets type metadata for a CLR type.

public abstract TomlTypeInfo? GetTypeInfo(Type type, TomlSerializerOptions options)

Parameters

type Type
The CLR type to resolve.
options TomlSerializerOptions
The serializer options in use.

Returns

TomlTypeInfo? The metadata for type, or null when not available.

ReportDeserializationError(TomlReader, TomlSourceSpan?, string)

TomlSerializerContext.cs

Reports an error found after a table was read, such as a missing required key. It is recorded with the other deserialization diagnostics, and TomlSerializerContext.ThrowIfDeserializationDiagnostics throws once every error of the table is found. It is thrown directly when the diagnostics cannot be recorded.

protected static void ReportDeserializationError(TomlReader reader, TomlSourceSpan? span, string message)

Parameters

reader TomlReader
The TOML reader.
span TomlSourceSpan?
The location of the error.
message string
The error message.

ReportDuplicateKey(TomlReader, string)

TomlSerializerContext.cs

Reports a key that maps to a member that was already read, such as Name and name when property names are case-insensitive. The error is recorded with the other deserialization diagnostics, and the value is skipped. It is thrown directly when the diagnostics cannot be recorded.

protected static void ReportDuplicateKey(TomlReader reader, string name)

Parameters

reader TomlReader
The TOML reader, positioned on the first token of the value.
name string
The key.

ResolveRuntimeConverterTypeInfo(TomlSerializerOptions, Type, Type[]?)

TomlSerializerContext.cs

Resolves converter-based metadata for a runtime converter registered on options.

protected static TomlTypeInfo? ResolveRuntimeConverterTypeInfo(TomlSerializerOptions options, Type type, Type[]? ignoredConverterTypes)

Parameters

options TomlSerializerOptions
The options that may contain runtime converters.
type Type
The type to resolve.
ignoredConverterTypes Type[]?
Converter types supplied by source-generation options that should not be treated as runtime overrides.

Returns

TomlTypeInfo? Converter-based metadata, or null when no runtime converter matches.

ThrowIfDeserializationDiagnostics(TomlReader, int, TomlSourceSpan?)

TomlSerializerContext.cs

Throws a TomlException when recoverable deserialization diagnostics were recorded since TomlSerializerContext.GetDeserializationDiagnosticCount returned diagnosticCount. The table that contains the value continues with its next value, so the errors of the rest of the document are reported as well.

protected static void ThrowIfDeserializationDiagnostics(TomlReader reader, int diagnosticCount, TomlSourceSpan? tableStartSpan)

Parameters

reader TomlReader
The TOML reader.
diagnosticCount int
The number of diagnostics when the table started.
tableStartSpan TomlSourceSpan?
The location of the start of the table, which identifies the value that was read.

TryAddDeserializationDiagnostic(TomlReader, TomlTokenType, TomlSourceSpan?, TomlException)

TomlSerializerContext.cs

Records a recoverable deserialization diagnostic and skips the current TOML value when the reader is still positioned on the same token that failed.

protected static bool TryAddDeserializationDiagnostic(TomlReader reader, TomlTokenType tokenType, TomlSourceSpan? span, TomlException exception)

Parameters

reader TomlReader
The TOML reader.
tokenType TomlTokenType
The token type before the read attempt.
span TomlSourceSpan?
The source span before the read attempt.
exception TomlException
The exception raised by the read attempt.

Returns

bool true when the diagnostic was recorded and the current value was skipped, or when the value was read and its errors were already recorded.

WritePropertyName(TomlWriter, string, TomlDottedKeyHandling?)

TomlSerializerContext.cs

Writes a TOML property name using an optional dotted-key handling override.

protected static void WritePropertyName(TomlWriter writer, string name, TomlDottedKeyHandling? dottedKeyHandling)

Parameters

writer TomlWriter
The TOML writer.
name string
The property name.
dottedKeyHandling TomlDottedKeyHandling?
The dotted-key handling override, or null to use the writer options.