YamlSourceGenerationOptionsAttribute Class

Specifies the default YamlSerializerOptions used by a source-generated YamlSerializerContext.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class YamlSourceGenerationOptionsAttribute : YamlAttribute

Remarks

This attribute is inspired by System.Text.Json's JsonSourceGenerationOptionsAttribute, but targets YamlSerializerOptions instead.

The Meziantou.Framework.Yaml source generator reads this attribute at compile time and emits a context that constructs an immutable YamlSerializerOptions instance. The generated context expects the same options instance to be used consistently at runtime.

Inheritance
YamlAttribute YamlSourceGenerationOptionsAttribute

Constructors

NameDescription
YamlSourceGenerationOptionsAttribute()

YamlSourceGenerationOptionsAttribute()

public YamlSourceGenerationOptionsAttribute()

No documentation is available.

Properties

NameDescription
BlockSequenceMappingStyleGets or sets how mappings are emitted when they appear as items in block sequences.
BlockSequenceSequenceStyleGets or sets how nested sequences are emitted when they appear as items in block sequences.
ConvertersGets or sets converter types to be instantiated and registered on the generated options instance.
DefaultIgnoreConditionGets or sets the default ignore condition for null/default values.
DictionaryKeyPolicyGets or sets the policy used to convert dictionary keys during serialization.
DiscriminatorStyleGets or sets how type discriminators are represented during polymorphic serialization.
DuplicateKeyHandlingGets or sets behavior when duplicate mapping keys are encountered while reading.
IgnoreReadOnlyFieldsGets or sets a value indicating whether read-only fields are ignored during serialization.
IgnoreReadOnlyPropertiesGets or sets a value indicating whether read-only properties are ignored during serialization.
IncludeFieldsGets or sets a value indicating whether public fields are included during serialization and deserialization.
IndentBlockSequencesGets or sets a value indicating whether a block sequence that is the value of a mapping key is indented relative to that mapping.
IndentSizeGets or sets the number of spaces to use when YamlSourceGenerationOptionsAttribute.WriteIndented is enabled.
InferClosedTypePolymorphismGets or sets a value indicating whether derived type registrations are inferred from the compiler-provided metadata of a closed type hierarchy.
MappingOrderGets or sets member ordering behavior for emitted mappings.
PreferPlainStyleGets or sets a value indicating whether plain scalar style should be preferred when possible.
PreferQuotedForAmbiguousScalarsGets or sets a value indicating whether quoted scalar style should be preferred for ambiguous scalars.
PreferredObjectCreationHandlingGets or sets the preferred object creation handling for members during deserialization.
PropertyNameCaseInsensitiveGets or sets a value indicating whether property name matching is case-insensitive.
PropertyNamingPolicyGets or sets the policy used to convert CLR property names.
ReferenceHandlingGets or sets object reference handling behavior.
RespectNullableAnnotationsGets or sets a value indicating whether nullable annotations are enforced during serialization and deserialization.
RespectRequiredConstructorParametersGets or sets a value indicating whether required constructor parameters must be present during deserialization.
SchemaGets or sets the schema used for scalar resolution.
SourceNameGets or sets an optional name for the YAML source.
StringStyleGets or sets the style used to emit string values.
TypeDiscriminatorPropertyNameGets or sets the property name used for discriminator-based polymorphism.
UnknownDerivedTypeHandlingGets or sets behavior when an unknown derived type discriminator is encountered.
UnmappedMemberHandlingGets or sets how unmapped YAML members are handled during object deserialization.
UnsafeAllowDeserializeFromTagTypeNameGets or sets a value indicating whether unregistered runtime type names from YAML tags are allowed during deserialization.
UseSchemaGets or sets a value indicating whether scalar deserialization should resolve through YamlSourceGenerationOptionsAttribute.Schema.
WriteIndentedGets or sets a value indicating whether emitted YAML should be indented.

Gets or sets how mappings are emitted when they appear as items in block sequences.

public YamlSequenceItemStyle BlockSequenceMappingStyle { get; set; }

Property value

YamlSequenceItemStyle

BlockSequenceSequenceStyle

YamlSourceGenerationOptionsAttribute.cs

Gets or sets how nested sequences are emitted when they appear as items in block sequences.

public YamlSequenceItemStyle BlockSequenceSequenceStyle { get; set; }

Property value

YamlSequenceItemStyle

Gets or sets converter types to be instantiated and registered on the generated options instance.

public Type[]? Converters { get; set; }

Property value

Type[]?

Remarks

Each converter type must derive from YamlConverter and expose a public parameterless constructor.

Gets or sets the default ignore condition for null/default values.

public YamlIgnoreCondition DefaultIgnoreCondition { get; set; }

Property value

YamlIgnoreCondition

Gets or sets the policy used to convert dictionary keys during serialization.

public YamlKnownNamingPolicy DictionaryKeyPolicy { get; set; }

Property value

YamlKnownNamingPolicy

Gets or sets how type discriminators are represented during polymorphic serialization.

public YamlTypeDiscriminatorStyle DiscriminatorStyle { get; set; }

Gets or sets behavior when duplicate mapping keys are encountered while reading.

public YamlDuplicateKeyHandling DuplicateKeyHandling { get; set; }

Gets or sets a value indicating whether read-only fields are ignored during serialization.

public bool IgnoreReadOnlyFields { get; set; }

Property value

bool

Gets or sets a value indicating whether read-only properties are ignored during serialization.

public bool IgnoreReadOnlyProperties { get; set; }

Property value

bool

Gets or sets a value indicating whether public fields are included during serialization and deserialization.

public bool IncludeFields { get; set; }

Property value

bool

Gets or sets a value indicating whether a block sequence that is the value of a mapping key is indented relative to that mapping.

public bool IndentBlockSequences { get; set; }

Gets or sets the number of spaces to use when YamlSourceGenerationOptionsAttribute.WriteIndented is enabled.

public int IndentSize { get; set; }

Property value

int

InferClosedTypePolymorphism

YamlSourceGenerationOptionsAttribute.cs

Gets or sets a value indicating whether derived type registrations are inferred from the compiler-provided metadata of a closed type hierarchy.

public bool InferClosedTypePolymorphism { get; set; }

Property value

bool

Remarks

This is the source-generation counterpart of YamlPolymorphismOptions.InferClosedTypePolymorphism. YamlPolymorphicAttribute.InferClosedTypePolymorphism overrides this value for the type it is applied to.

Gets or sets member ordering behavior for emitted mappings.

public YamlMappingOrderPolicy MappingOrder { get; set; }

Gets or sets a value indicating whether plain scalar style should be preferred when possible.

public bool PreferPlainStyle { get; set; }

Property value

bool

PreferQuotedForAmbiguousScalars

YamlSourceGenerationOptionsAttribute.cs

Gets or sets a value indicating whether quoted scalar style should be preferred for ambiguous scalars.

public bool PreferQuotedForAmbiguousScalars { get; set; }

Property value

bool

PreferredObjectCreationHandling

YamlSourceGenerationOptionsAttribute.cs

Gets or sets the preferred object creation handling for members during deserialization.

public YamlObjectCreationHandling PreferredObjectCreationHandling { get; set; }

PropertyNameCaseInsensitive

YamlSourceGenerationOptionsAttribute.cs

Gets or sets a value indicating whether property name matching is case-insensitive.

public bool PropertyNameCaseInsensitive { get; set; }

Property value

bool

Gets or sets the policy used to convert CLR property names.

public YamlKnownNamingPolicy PropertyNamingPolicy { get; set; }

Property value

YamlKnownNamingPolicy

Gets or sets object reference handling behavior.

public YamlReferenceHandling ReferenceHandling { get; set; }

Property value

YamlReferenceHandling

RespectNullableAnnotations

YamlSourceGenerationOptionsAttribute.cs

Gets or sets a value indicating whether nullable annotations are enforced during serialization and deserialization.

public bool RespectNullableAnnotations { get; set; }

Property value

bool

RespectRequiredConstructorParameters

YamlSourceGenerationOptionsAttribute.cs

Gets or sets a value indicating whether required constructor parameters must be present during deserialization.

public bool RespectRequiredConstructorParameters { get; set; }

Property value

bool

Gets or sets the schema used for scalar resolution.

public YamlSchemaKind Schema { get; set; }

Property value

YamlSchemaKind

Gets or sets an optional name for the YAML source.

public string? SourceName { get; set; }

Property value

string?

Remarks

This value is used to annotate YamlException messages with a source name (for example, a file path) when reporting parse errors.

Gets or sets the style used to emit string values.

public ScalarStyle StringStyle { get; set; }

TypeDiscriminatorPropertyName

YamlSourceGenerationOptionsAttribute.cs

Gets or sets the property name used for discriminator-based polymorphism.

public string? TypeDiscriminatorPropertyName { get; set; }

Property value

string?

UnknownDerivedTypeHandling

YamlSourceGenerationOptionsAttribute.cs

Gets or sets behavior when an unknown derived type discriminator is encountered.

public YamlUnknownDerivedTypeHandling UnknownDerivedTypeHandling { get; set; }

Gets or sets how unmapped YAML members are handled during object deserialization.

public YamlUnmappedMemberHandling UnmappedMemberHandling { get; set; }

UnsafeAllowDeserializeFromTagTypeName

YamlSourceGenerationOptionsAttribute.cs

Gets or sets a value indicating whether unregistered runtime type names from YAML tags are allowed during deserialization.

public bool UnsafeAllowDeserializeFromTagTypeName { get; set; }

Property value

bool

Gets or sets a value indicating whether scalar deserialization should resolve through YamlSourceGenerationOptionsAttribute.Schema.

public bool UseSchema { get; set; }

Property value

bool

Gets or sets a value indicating whether emitted YAML should be indented.

public bool WriteIndented { get; set; }

Property value

bool

Remarks

When disabled, collections are written using the flow style, which keeps the whole document on a single line. See YamlSerializerOptions.WriteIndented.