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
| Name | Description |
|---|---|
| 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.csInitializes a new instance of the TomlPolymorphicTypeInfo<TBase> class.
public TomlPolymorphicTypeInfo(TomlSerializerOptions options, TomlTypeInfo<TBase>? baseTypeInfo, string? discriminatorPropertyName, IReadOnlyDictionary<string, TomlTypeInfo> derivedTypeInfoByDiscriminator)Parameters
optionsTomlSerializerOptions- The serializer options.
baseTypeInfoTomlTypeInfo<TBase>?- Optional base type metadata used when falling back to base types.
discriminatorPropertyNamestring?- Optional discriminator key name. When
nullor empty,TomlSerializerOptions.PolymorphismOptionsis used. derivedTypeInfoByDiscriminatorIReadOnlyDictionary<string, TomlTypeInfo>- A mapping from discriminator values to derived type metadata.
Exceptions
ArgumentNullException- Thrown when
optionsorderivedTypeInfoByDiscriminatorisnull. TomlException- Thrown when the mapping is invalid.
TomlPolymorphicTypeInfo(TomlSerializerOptions, TomlTypeInfo<TBase>?, string?, IReadOnlyDictionary<string, TomlTypeInfo>, TomlTypeInfo?)
TomlPolymorphicTypeInfo.csInitializes 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
optionsTomlSerializerOptions- The serializer options.
baseTypeInfoTomlTypeInfo<TBase>?- Optional base type metadata used when falling back to base types.
discriminatorPropertyNamestring?- Optional discriminator key name. When
nullor empty,TomlSerializerOptions.PolymorphismOptionsis used. derivedTypeInfoByDiscriminatorIReadOnlyDictionary<string, TomlTypeInfo>- A mapping from discriminator values to derived type metadata.
defaultDerivedTypeInfoTomlTypeInfo?- Optional default derived type metadata, used when the discriminator is missing or unrecognized.
Exceptions
ArgumentNullException- Thrown when
optionsorderivedTypeInfoByDiscriminatorisnull. TomlException- Thrown when the mapping is invalid.
TomlPolymorphicTypeInfo(TomlSerializerOptions, TomlTypeInfo<TBase>?, string?, IReadOnlyDictionary<string, TomlTypeInfo>, TomlTypeInfo?, TomlUnknownDerivedTypeHandling?)
TomlPolymorphicTypeInfo.csInitializes 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
optionsTomlSerializerOptions- The serializer options.
baseTypeInfoTomlTypeInfo<TBase>?- Optional base type metadata used when falling back to base types.
discriminatorPropertyNamestring?- Optional discriminator key name. When
nullor empty,TomlSerializerOptions.PolymorphismOptionsis used. derivedTypeInfoByDiscriminatorIReadOnlyDictionary<string, TomlTypeInfo>- A mapping from discriminator values to derived type metadata.
defaultDerivedTypeInfoTomlTypeInfo?- Optional default derived type metadata, used when the discriminator is missing or unrecognized.
unknownDerivedTypeHandlingTomlUnknownDerivedTypeHandling?- Optional override for unknown discriminator handling. When
nullorTomlUnknownDerivedTypeHandling.Unspecified, uses options default.
Exceptions
ArgumentNullException- Thrown when
optionsorderivedTypeInfoByDiscriminatorisnull. ArgumentOutOfRangeException- Thrown when
unknownDerivedTypeHandlingis not a defined value. TomlException- Thrown when the mapping is invalid, such as a derived type that does not derive from
TBase.
Properties
| Name | Description |
|---|---|
| WritesTable | Gets a value indicating whether this metadata writes values as TOML tables. |
WritesTable
TomlPolymorphicTypeInfo.csMethods
| Name | Description |
|---|---|
| Read(TomlReader) | Reads a value from an existing TOML reader. |
| Write(TomlWriter, TBase) | Writes a value to an existing TOML writer. |
Read(TomlReader)
TomlPolymorphicTypeInfo.csReads a value from an existing TOML reader.
public override TBase? Read(TomlReader reader)Write(TomlWriter, TBase)
TomlPolymorphicTypeInfo.csWrites a value to an existing TOML writer.
public override void Write(TomlWriter writer, TBase value)Parameters
writerTomlWritervalueTBase