TomlSerializerContext Class
Base type for source-generated TOML serializer contexts.
public abstract class TomlSerializerContext : ITomlTypeInfoResolver- Implements
Constructors
| Name | Description |
|---|---|
| TomlSerializerContext() | Initializes a new instance of the TomlSerializerContext class. |
| TomlSerializerContext(TomlSerializerOptions) | Initializes a new instance of the TomlSerializerContext class. |
TomlSerializerContext overloads
TomlSerializerContext()
TomlSerializerContext.csInitializes a new instance of the TomlSerializerContext class.
protected TomlSerializerContext()TomlSerializerContext(TomlSerializerOptions)
TomlSerializerContext.csInitializes a new instance of the TomlSerializerContext class.
protected TomlSerializerContext(TomlSerializerOptions options)Parameters
optionsTomlSerializerOptions- The options used by this context.
Properties
| Name | Description |
|---|---|
| Options | Gets the options instance associated with this context. |
Options
TomlSerializerContext.csGets the options instance associated with this context.
public TomlSerializerOptions Options { get; }Property value
Methods
| Name | Description |
|---|---|
| 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.csAdds 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
existingValueobject- The existing collection instance.
incomingCollectionIEnumerable<T>- The values to add.
Returns
object The populated collection instance.
AddSingleElementToSingleOrArrayCollection<T>(object, T)
TomlSerializerContext.csAdds a single element to an existing collection for source-generated TomlSingleOrArrayAttribute handling.
ApplyPropertyMetadata(TomlWriter, string, TomlPropertyMetadata)
TomlSerializerContext.csApplies formatting metadata for a TOML property currently being written by source-generated metadata.
protected static void ApplyPropertyMetadata(TomlWriter writer, string name, TomlPropertyMetadata metadata)Parameters
writerTomlWriter- The TOML writer.
namestring- The property name.
metadataTomlPropertyMetadata- The metadata to merge.
AttachPropertiesMetadata<T>(TomlWriter, T)
TomlSerializerContext.csWrites 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
writerTomlWriter- The writer, after the start of the table.
valueT- The instance.
BeginPropertiesMetadata<T>(TomlReader)
TomlSerializerContext.csStarts 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
readerTomlReader- The reader, positioned on
TomlTokenType.StartTable.
Returns
TomlPropertiesMetadata? The metadata to pass to TomlSerializerContext.EndPropertiesMetadata, or null.
CanPopulateSingleOrArrayCollection<T>(object)
TomlSerializerContext.csDetermines whether an existing collection can be populated for source-generated TomlSingleOrArrayAttribute handling.
CaptureValue(TomlReader)
TomlSerializerContext.csReads 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
readerTomlReader- 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.csCreates 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
optionsTomlSerializerOptions- The serializer options.
converterTomlConverter- 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.csCreates 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)CreateConfigurationException(string, Exception?)
TomlSerializerContext.csCreates 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
messagestring- The error message.
innerExceptionException?- The exception that caused the error.
Returns
TomlException The exception to throw.
CreateConverterTypeInfo<T>(TomlSerializerOptions, TomlConverter<T>)
TomlSerializerContext.csCreates 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
optionsTomlSerializerOptions- The serializer options.
converterTomlConverter<T>- The converter instance.
Returns
TomlTypeInfo<T> Converter-based TOML metadata.
CreateNullableStringEnumTypeInfo<TEnum>(TomlSerializerOptions)
TomlSerializerContext.csCreates metadata for a nullable enum type that writes values as strings.
protected static TomlTypeInfo<TEnum?> CreateNullableStringEnumTypeInfo<TEnum>(TomlSerializerOptions options) where TEnum : struct, EnumType parameters
TEnum- The enum type.
Parameters
optionsTomlSerializerOptions- The serializer options.
Returns
TomlTypeInfo<TEnum?> The nullable enum metadata.
CreateSingleElementArray<T>(T)
TomlSerializerContext.csCreates 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
elementT- The element to place in the collection.
Returns
T[] An array containing element.
CreateSingleElementCollection<TCollection, TElement>(TElement)
TomlSerializerContext.csCreates 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
elementTElement- The element to place in the collection.
Returns
TCollection A collection containing element.
CreateSingleElementHashSet<T>(T)
TomlSerializerContext.csCreates 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
elementT- The element to place in the collection.
Returns
HashSet<T> A hash set containing element.
CreateSingleElementImmutableArray<T>(T)
TomlSerializerContext.csCreates 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
elementT- The element to place in the collection.
Returns
ImmutableArray<T> An immutable array containing element.
CreateSingleElementImmutableHashSet<T>(T)
TomlSerializerContext.csCreates 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
elementT- The element to place in the collection.
Returns
ImmutableHashSet<T> An immutable hash set containing element.
CreateSingleElementImmutableList<T>(T)
TomlSerializerContext.csCreates 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
elementT- The element to place in the collection.
Returns
ImmutableList<T> An immutable list containing element.
CreateSingleElementList<T>(T)
TomlSerializerContext.csCreates 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
elementT- The element to place in the collection.
Returns
List<T> A list containing element.
CreateSourceGeneratedArrayTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedConcreteDictionaryTypeInfo<TDictionary, TValue>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
TDictionaryTValue
Parameters
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedDictionaryTypeInfo<TDictionary, TValue>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
TDictionaryTValue
Parameters
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedHashSetBackedEnumerableTypeInfo<TEnumerable, TElement>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
TEnumerableTElement
Parameters
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedHashSetTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
TomlTypeInfo<HashSet<TElement>>
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedImmutableArrayTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
TomlTypeInfo<ImmutableArray<TElement>>
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedImmutableHashSetTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
TomlTypeInfo<ImmutableHashSet<TElement>>
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedImmutableListTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
contextTomlSerializerContextoptionsTomlSerializerOptions?
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.csCreates 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
TEnumerableTElement
Parameters
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedListTypeInfo<TElement>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedMutableCollectionTypeInfo<TCollection, TElement>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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
TCollectionTElement
Parameters
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateSourceGeneratedNullableTypeInfo<T>(TomlSerializerContext, TomlSerializerOptions?)
TomlSerializerContext.csCreates 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 : structType parameters
T
Parameters
contextTomlSerializerContextoptionsTomlSerializerOptions?
Returns
Remarks
This method avoids reflection-based metadata resolution, making it compatible with trimming and NativeAOT.
CreateStringEnumTypeInfo<TEnum>(TomlSerializerOptions)
TomlSerializerContext.csCreates metadata for an enum type that writes values as strings.
protected static TomlTypeInfo<TEnum> CreateStringEnumTypeInfo<TEnum>(TomlSerializerOptions options) where TEnum : struct, EnumType parameters
TEnum- The enum type.
Parameters
optionsTomlSerializerOptions- The serializer options.
Returns
TomlTypeInfo<TEnum> The enum metadata.
EndPropertiesMetadata<T>(TomlReader, TomlPropertiesMetadata?, T)
TomlSerializerContext.csStores 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
readerTomlReader- The reader.
metadataTomlPropertiesMetadata?- The metadata returned by
TomlSerializerContext.BeginPropertiesMetadata. valueT- The instance read from the table.
GetBuiltInTypeInfo<T>(TomlSerializerOptions)
TomlSerializerContext.csResolves built-in type metadata for a known scalar/container type.
protected static TomlTypeInfo<T> GetBuiltInTypeInfo<T>(TomlSerializerOptions options)Type parameters
T
Parameters
optionsTomlSerializerOptions
Returns
Remarks
This method exists to support source-generated contexts without requiring generated code to reference internal resolver types.
GetDeserializationDiagnosticCount(TomlReader)
TomlSerializerContext.csGets 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)GetTypeInfo(Type, TomlSerializerOptions)
Gets type metadata for a CLR type.
public abstract TomlTypeInfo? GetTypeInfo(Type type, TomlSerializerOptions options)Parameters
typeType- The CLR type to resolve.
optionsTomlSerializerOptions- The serializer options in use.
Returns
TomlTypeInfo? The metadata for type, or null when not available.
ReportDeserializationError(TomlReader, TomlSourceSpan?, string)
TomlSerializerContext.csReports 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
readerTomlReader- The TOML reader.
spanTomlSourceSpan?- The location of the error.
messagestring- The error message.
ReportDuplicateKey(TomlReader, string)
TomlSerializerContext.csReports 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
readerTomlReader- The TOML reader, positioned on the first token of the value.
namestring- The key.
ResolveRuntimeConverterTypeInfo(TomlSerializerOptions, Type, Type[]?)
TomlSerializerContext.csResolves converter-based metadata for a runtime converter registered on options.
protected static TomlTypeInfo? ResolveRuntimeConverterTypeInfo(TomlSerializerOptions options, Type type, Type[]? ignoredConverterTypes)Parameters
optionsTomlSerializerOptions- The options that may contain runtime converters.
typeType- The type to resolve.
ignoredConverterTypesType[]?- 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.csThrows 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
readerTomlReader- The TOML reader.
diagnosticCountint- The number of diagnostics when the table started.
tableStartSpanTomlSourceSpan?- The location of the start of the table, which identifies the value that was read.
TryAddDeserializationDiagnostic(TomlReader, TomlTokenType, TomlSourceSpan?, TomlException)
TomlSerializerContext.csRecords 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
readerTomlReader- The TOML reader.
tokenTypeTomlTokenType- The token type before the read attempt.
spanTomlSourceSpan?- The source span before the read attempt.
exceptionTomlException- 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.csWrites a TOML property name using an optional dotted-key handling override.
protected static void WritePropertyName(TomlWriter writer, string name, TomlDottedKeyHandling? dottedKeyHandling)Parameters
writerTomlWriter- The TOML writer.
namestring- The property name.
dottedKeyHandlingTomlDottedKeyHandling?- The dotted-key handling override, or
nullto use the writer options.