TomlPolymorphicTypeInfo<TBase> Class

Provides source-generator-friendly discriminator-based polymorphism support for TOML serialization.

public sealed class TomlPolymorphicTypeInfo<TBase> : TomlTypeInfo<TBase>

Type parameters

TBase
The base type.
Inheritance
TomlTypeInfo<TBase> TomlPolymorphicTypeInfo<TBase>

Constructors

NameDescription
TomlPolymorphicTypeInfo(TomlSerializerOptions, TomlTypeInfo<TBase>?, string?, IReadOnlyDictionary<string, TomlTypeInfo>)Initializes a new instance of the TomlPolymorphicTypeInfo<TBase> class.
TomlPolymorphicTypeInfo(TomlSerializerOptions, TomlTypeInfo<TBase>?, string?, IReadOnlyDictionary<string, TomlTypeInfo>, TomlTypeInfo?)Initializes a new instance of the TomlPolymorphicTypeInfo<TBase> class with an optional default derived type.
TomlPolymorphicTypeInfo(TomlSerializerOptions, TomlTypeInfo<TBase>?, string?, IReadOnlyDictionary<string, TomlTypeInfo>, TomlTypeInfo?, TomlUnknownDerivedTypeHandling?)Initializes a new instance of the TomlPolymorphicTypeInfo<TBase> class with optional default derived type and unknown handling override.

TomlPolymorphicTypeInfo overloads

TomlPolymorphicTypeInfo(TomlSerializerOptions, TomlTypeInfo<TBase>?, string?, IReadOnlyDictionary<string, TomlTypeInfo>)

TomlPolymorphicTypeInfo.cs

Initializes a new instance of the TomlPolymorphicTypeInfo<TBase> class.

public TomlPolymorphicTypeInfo(TomlSerializerOptions options, TomlTypeInfo<TBase>? baseTypeInfo, string? discriminatorPropertyName, IReadOnlyDictionary<string, TomlTypeInfo> derivedTypeInfoByDiscriminator)
Parameters
options TomlSerializerOptions
The serializer options.
baseTypeInfo TomlTypeInfo<TBase>?
Optional base type metadata used when falling back to base types.
discriminatorPropertyName string?
Optional discriminator key name. When null or empty, TomlSerializerOptions.PolymorphismOptions is used.
derivedTypeInfoByDiscriminator IReadOnlyDictionary<string, TomlTypeInfo>
A mapping from discriminator values to derived type metadata.
Exceptions
ArgumentNullException
Thrown when options or derivedTypeInfoByDiscriminator is null.
TomlException
Thrown when the mapping is invalid.

TomlPolymorphicTypeInfo(TomlSerializerOptions, TomlTypeInfo<TBase>?, string?, IReadOnlyDictionary<string, TomlTypeInfo>, TomlTypeInfo?)

TomlPolymorphicTypeInfo.cs

Initializes a new instance of the TomlPolymorphicTypeInfo<TBase> class with an optional default derived type.

public TomlPolymorphicTypeInfo(TomlSerializerOptions options, TomlTypeInfo<TBase>? baseTypeInfo, string? discriminatorPropertyName, IReadOnlyDictionary<string, TomlTypeInfo> derivedTypeInfoByDiscriminator, TomlTypeInfo? defaultDerivedTypeInfo)
Parameters
options TomlSerializerOptions
The serializer options.
baseTypeInfo TomlTypeInfo<TBase>?
Optional base type metadata used when falling back to base types.
discriminatorPropertyName string?
Optional discriminator key name. When null or empty, TomlSerializerOptions.PolymorphismOptions is used.
derivedTypeInfoByDiscriminator IReadOnlyDictionary<string, TomlTypeInfo>
A mapping from discriminator values to derived type metadata.
defaultDerivedTypeInfo TomlTypeInfo?
Optional default derived type metadata, used when the discriminator is missing or unrecognized.
Exceptions
ArgumentNullException
Thrown when options or derivedTypeInfoByDiscriminator is null.
TomlException
Thrown when the mapping is invalid.

TomlPolymorphicTypeInfo(TomlSerializerOptions, TomlTypeInfo<TBase>?, string?, IReadOnlyDictionary<string, TomlTypeInfo>, TomlTypeInfo?, TomlUnknownDerivedTypeHandling?)

TomlPolymorphicTypeInfo.cs

Initializes a new instance of the TomlPolymorphicTypeInfo<TBase> class with optional default derived type and unknown handling override.

public TomlPolymorphicTypeInfo(TomlSerializerOptions options, TomlTypeInfo<TBase>? baseTypeInfo, string? discriminatorPropertyName, IReadOnlyDictionary<string, TomlTypeInfo> derivedTypeInfoByDiscriminator, TomlTypeInfo? defaultDerivedTypeInfo, TomlUnknownDerivedTypeHandling? unknownDerivedTypeHandling)
Parameters
options TomlSerializerOptions
The serializer options.
baseTypeInfo TomlTypeInfo<TBase>?
Optional base type metadata used when falling back to base types.
discriminatorPropertyName string?
Optional discriminator key name. When null or empty, TomlSerializerOptions.PolymorphismOptions is used.
derivedTypeInfoByDiscriminator IReadOnlyDictionary<string, TomlTypeInfo>
A mapping from discriminator values to derived type metadata.
defaultDerivedTypeInfo TomlTypeInfo?
Optional default derived type metadata, used when the discriminator is missing or unrecognized.
unknownDerivedTypeHandling TomlUnknownDerivedTypeHandling?
Optional override for unknown discriminator handling. When null or TomlUnknownDerivedTypeHandling.Unspecified, uses options default.
Exceptions
ArgumentNullException
Thrown when options or derivedTypeInfoByDiscriminator is null.
ArgumentOutOfRangeException
Thrown when unknownDerivedTypeHandling is not a defined value.
TomlException
Thrown when the mapping is invalid, such as a derived type that does not derive from TBase.

Properties

NameDescription
WritesTableGets a value indicating whether this metadata writes values as TOML tables.

Gets a value indicating whether this metadata writes values as TOML tables.

public override bool WritesTable { get; }

Property value

bool

Methods

NameDescription
Read(TomlReader)Reads a value from an existing TOML reader.
Write(TomlWriter, TBase)Writes a value to an existing TOML writer.

Reads a value from an existing TOML reader.

public override TBase? Read(TomlReader reader)

Parameters

reader TomlReader

Returns

TBase?

Write(TomlWriter, TBase)

TomlPolymorphicTypeInfo.cs

Writes a value to an existing TOML writer.

public override void Write(TomlWriter writer, TBase value)

Parameters

writer TomlWriter
value TBase