YamlSourceGenerationOptionsAttribute Class
Specifies the default YamlSerializerOptions used by a source-generated YamlSerializerContext.
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class YamlSourceGenerationOptionsAttribute : YamlAttributeRemarks
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
YamlAttributeYamlSourceGenerationOptionsAttribute
Constructors
| Name | Description |
|---|---|
| YamlSourceGenerationOptionsAttribute() |
YamlSourceGenerationOptionsAttribute()
public YamlSourceGenerationOptionsAttribute()No documentation is available.
Properties
| Name | Description |
|---|---|
| BlockSequenceMappingStyle | Gets or sets how mappings are emitted when they appear as items in block sequences. |
| BlockSequenceSequenceStyle | Gets or sets how nested sequences are emitted when they appear as items in block sequences. |
| Converters | Gets or sets converter types to be instantiated and registered on the generated options instance. |
| DefaultIgnoreCondition | Gets or sets the default ignore condition for null/default values. |
| DictionaryKeyPolicy | Gets or sets the policy used to convert dictionary keys during serialization. |
| DiscriminatorStyle | Gets or sets how type discriminators are represented during polymorphic serialization. |
| DuplicateKeyHandling | Gets or sets behavior when duplicate mapping keys are encountered while reading. |
| IgnoreReadOnlyFields | Gets or sets a value indicating whether read-only fields are ignored during serialization. |
| IgnoreReadOnlyProperties | Gets or sets a value indicating whether read-only properties are ignored during serialization. |
| IncludeFields | Gets or sets a value indicating whether public fields are included during serialization and deserialization. |
| IndentBlockSequences | Gets or sets a value indicating whether a block sequence that is the value of a mapping key is indented relative to that mapping. |
| IndentSize | Gets or sets the number of spaces to use when YamlSourceGenerationOptionsAttribute.WriteIndented is enabled. |
| InferClosedTypePolymorphism | Gets or sets a value indicating whether derived type registrations are inferred from the compiler-provided metadata of a closed type hierarchy. |
| MappingOrder | Gets or sets member ordering behavior for emitted mappings. |
| PreferPlainStyle | Gets or sets a value indicating whether plain scalar style should be preferred when possible. |
| PreferQuotedForAmbiguousScalars | Gets or sets a value indicating whether quoted scalar style should be preferred for ambiguous scalars. |
| PreferredObjectCreationHandling | Gets or sets the preferred object creation handling for members during deserialization. |
| PropertyNameCaseInsensitive | Gets or sets a value indicating whether property name matching is case-insensitive. |
| PropertyNamingPolicy | Gets or sets the policy used to convert CLR property names. |
| ReferenceHandling | Gets or sets object reference handling behavior. |
| RespectNullableAnnotations | Gets or sets a value indicating whether nullable annotations are enforced during serialization and deserialization. |
| RespectRequiredConstructorParameters | Gets or sets a value indicating whether required constructor parameters must be present during deserialization. |
| Schema | Gets or sets the schema used for scalar resolution. |
| SourceName | Gets or sets an optional name for the YAML source. |
| StringStyle | Gets or sets the style used to emit string values. |
| TypeDiscriminatorPropertyName | Gets or sets the property name used for discriminator-based polymorphism. |
| UnknownDerivedTypeHandling | Gets or sets behavior when an unknown derived type discriminator is encountered. |
| UnmappedMemberHandling | Gets or sets how unmapped YAML members are handled during object deserialization. |
| UnsafeAllowDeserializeFromTagTypeName | Gets or sets a value indicating whether unregistered runtime type names from YAML tags are allowed during deserialization. |
| UseSchema | Gets or sets a value indicating whether scalar deserialization should resolve through YamlSourceGenerationOptionsAttribute.Schema. |
| WriteIndented | Gets or sets a value indicating whether emitted YAML should be indented. |
BlockSequenceMappingStyle
YamlSourceGenerationOptionsAttribute.csGets or sets how mappings are emitted when they appear as items in block sequences.
public YamlSequenceItemStyle BlockSequenceMappingStyle { get; set; }Property value
BlockSequenceSequenceStyle
YamlSourceGenerationOptionsAttribute.csGets or sets how nested sequences are emitted when they appear as items in block sequences.
public YamlSequenceItemStyle BlockSequenceSequenceStyle { get; set; }Property value
Converters
YamlSourceGenerationOptionsAttribute.csGets 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.
DefaultIgnoreCondition
YamlSourceGenerationOptionsAttribute.csGets or sets the default ignore condition for null/default values.
public YamlIgnoreCondition DefaultIgnoreCondition { get; set; }Property value
DictionaryKeyPolicy
YamlSourceGenerationOptionsAttribute.csGets or sets the policy used to convert dictionary keys during serialization.
public YamlKnownNamingPolicy DictionaryKeyPolicy { get; set; }Property value
DiscriminatorStyle
YamlSourceGenerationOptionsAttribute.csGets or sets how type discriminators are represented during polymorphic serialization.
public YamlTypeDiscriminatorStyle DiscriminatorStyle { get; set; }Property value
DuplicateKeyHandling
YamlSourceGenerationOptionsAttribute.csGets or sets behavior when duplicate mapping keys are encountered while reading.
public YamlDuplicateKeyHandling DuplicateKeyHandling { get; set; }Property value
IgnoreReadOnlyFields
YamlSourceGenerationOptionsAttribute.csIgnoreReadOnlyProperties
YamlSourceGenerationOptionsAttribute.csIncludeFields
YamlSourceGenerationOptionsAttribute.csIndentBlockSequences
YamlSourceGenerationOptionsAttribute.csGets 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; }IndentSize
YamlSourceGenerationOptionsAttribute.csGets or sets the number of spaces to use when YamlSourceGenerationOptionsAttribute.WriteIndented is enabled.
public int IndentSize { get; set; }Property value
InferClosedTypePolymorphism
YamlSourceGenerationOptionsAttribute.csGets 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
Remarks
This is the source-generation counterpart of YamlPolymorphismOptions.InferClosedTypePolymorphism. YamlPolymorphicAttribute.InferClosedTypePolymorphism overrides this value for the type it is applied to.
MappingOrder
YamlSourceGenerationOptionsAttribute.csGets or sets member ordering behavior for emitted mappings.
public YamlMappingOrderPolicy MappingOrder { get; set; }Property value
PreferPlainStyle
YamlSourceGenerationOptionsAttribute.csPreferQuotedForAmbiguousScalars
YamlSourceGenerationOptionsAttribute.csPreferredObjectCreationHandling
YamlSourceGenerationOptionsAttribute.csGets or sets the preferred object creation handling for members during deserialization.
public YamlObjectCreationHandling PreferredObjectCreationHandling { get; set; }Property value
PropertyNameCaseInsensitive
YamlSourceGenerationOptionsAttribute.csPropertyNamingPolicy
YamlSourceGenerationOptionsAttribute.csGets or sets the policy used to convert CLR property names.
public YamlKnownNamingPolicy PropertyNamingPolicy { get; set; }Property value
ReferenceHandling
YamlSourceGenerationOptionsAttribute.csGets or sets object reference handling behavior.
public YamlReferenceHandling ReferenceHandling { get; set; }Property value
RespectNullableAnnotations
YamlSourceGenerationOptionsAttribute.csRespectRequiredConstructorParameters
YamlSourceGenerationOptionsAttribute.csGets or sets the schema used for scalar resolution.
public YamlSchemaKind Schema { get; set; }Property value
SourceName
YamlSourceGenerationOptionsAttribute.csGets or sets an optional name for the YAML source.
public string? SourceName { get; set; }Property value
Remarks
This value is used to annotate YamlException messages with a source name (for example, a file path) when reporting parse errors.
StringStyle
YamlSourceGenerationOptionsAttribute.csGets or sets the style used to emit string values.
public ScalarStyle StringStyle { get; set; }TypeDiscriminatorPropertyName
YamlSourceGenerationOptionsAttribute.csUnknownDerivedTypeHandling
YamlSourceGenerationOptionsAttribute.csGets or sets behavior when an unknown derived type discriminator is encountered.
public YamlUnknownDerivedTypeHandling UnknownDerivedTypeHandling { get; set; }Property value
UnmappedMemberHandling
YamlSourceGenerationOptionsAttribute.csGets or sets how unmapped YAML members are handled during object deserialization.
public YamlUnmappedMemberHandling UnmappedMemberHandling { get; set; }Property value
UnsafeAllowDeserializeFromTagTypeName
YamlSourceGenerationOptionsAttribute.csGets or sets a value indicating whether scalar deserialization should resolve through YamlSourceGenerationOptionsAttribute.Schema.
public bool UseSchema { get; set; }Property value
WriteIndented
YamlSourceGenerationOptionsAttribute.csGets or sets a value indicating whether emitted YAML should be indented.
public bool WriteIndented { get; set; }Property value
Remarks
When disabled, collections are written using the flow style, which keeps the whole document on a single line. See YamlSerializerOptions.WriteIndented.