YamlSerializerOptions class
Provides options to be used with YamlSerializer.
Namespace: System.Text.Yaml · Assembly: Styml.dll
public sealed class YamlSerializerOptions
Provides options to be used with YamlSerializer.
ConstructorsLink to this heading
Constructs a new YamlSerializerOptions instance.
public YamlSerializerOptions();
Copies the options from a YamlSerializerOptions instance to a new instance.
public YamlSerializerOptions(YamlSerializerOptions options);
Parameters
options: TheYamlSerializerOptionsinstance to copy options from.
| Exception | Condition |
|---|---|
| ArgumentNullException | options is null. |
Constructs a new YamlSerializerOptions instance with a predefined set of options determined by the specified YamlSerializerDefaults.
public YamlSerializerOptions(YamlSerializerDefaults defaults);
Parameters
defaults: TheYamlSerializerDefaultsto reason about.
PropertiesLink to this heading
AcceptLenientScalarsLink to this heading
Gets or sets whether typed reads accept scalars that YamlDotNet or SharpYaml resolve although no YAML standard does (YamlReaderOptions.AcceptLenientScalars, which lists them): booleans and numbers in other cases, other float names, quoted, block and tagged booleans, numbers and enum numbers ('12'), padded dates, times and GUIDs (' 2001-01-01 '), null in any case as null, and a null into a non-nullable value type as its default. A constructor parameter refuses that null, as without the option, where a property of the same type takes the default. Under YamlSchemaKind.Json, an untagged plain scalar that matches no JSON form (foo, ~, the empty scalar) reads as a string rather than an error, a superset of SharpYaml's reading (True also reads into a Boolean, which SharpYaml's JSON schema refuses). Off by default. When deserializing from a Utf8YamlReader, the reader's own option applies. A converter of your own receives NuLL as a YamlTokenType.String token and a null as the YamlTokenType.Null token, as without the option. Strings such as NuLl are written plain by default and read back as null with this option; set YamlSerializerOptions.QuoteForLenientReaders where the same documents are written.
public bool AcceptLenientScalars { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
AllowDuplicatePropertiesLink to this heading
Defines whether duplicate property names are allowed when deserializing YAML objects: a view of YamlSerializerOptions.DuplicateKeyHandling, true unless it is YamlDuplicateKeyHandling.Error.
public bool AllowDuplicateProperties { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
Setting it to true selects YamlDuplicateKeyHandling.LastWins and false selects YamlDuplicateKeyHandling.Error, which throws a YamlException when a duplicate property name is encountered during deserialization. By default it is false.
Duplicate property names are not allowed in serialization.
AllowOutOfOrderMetadataPropertiesLink to this heading
Allows YAML metadata properties to be specified after regular properties in a deserialized YAML object.
public bool AllowOutOfOrderMetadataProperties { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
When set to true, removes the requirement that YAML metadata properties such as $id and $type should be specified at the very start of the deserialized YAML object. It should be noted that enabling this setting can result in over-buffering when deserializing large YAML payloads in the context of streaming deserialization.
AllowTrailingCommasLink to this heading
Kept for source compatibility with System.Text.Json; it has no effect. YAML flow collections always allow (and ignore) one trailing comma before their closing bracket.
public bool AllowTrailingCommas { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
The JSON grammar that read this option was deleted in M7a (decision D8); setting it changes nothing.
ConvertersLink to this heading
The list of custom converters.
public IList<YamlConverter> Converters { get; }
Once serialization or deserialization occurs, the list cannot be modified.
DefaultLink to this heading
Gets a read-only, singleton instance of YamlSerializerOptions that uses the default configuration.
public static YamlSerializerOptions Default { get; }
Each YamlSerializerOptions instance encapsulates its own serialization metadata caches, so using fresh default instances every time one is needed can result in redundant recomputation of converters. This property provides a shared instance that can be consumed by any number of components without necessitating any converter recomputation.
DefaultBufferSizeLink to this heading
The default buffer size in bytes used when creating temporary buffers.
public int DefaultBufferSize { get; set; }
| Exception | Condition |
|---|---|
| ArgumentException | Thrown when the buffer size is less than 1. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
The default size is 16K.
DefaultIgnoreConditionLink to this heading
Specifies a condition to determine when properties with default values are ignored during serialization or deserialization. The default value is YamlIgnoreCondition.Never.
public YamlIgnoreCondition DefaultIgnoreCondition { get; set; }
| Exception | Condition |
|---|---|
| ArgumentException | Thrown if this property is set to YamlIgnoreCondition.Always. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
DefaultScalarStyleLink to this heading
Gets or sets, in block style, the style for every string value that has no style of its own: no member YamlScalarStyleAttribute, no converter's Utf8YamlWriter.WriteScalarStyle and no source style kept by a YamlDocument or a YamlNode; for a string with a line break, a YamlSerializerOptions.MultiLineStringStyle that is set goes first. YamlScalarStyle.None, the default, leaves the writer's own choice. The style is applied where the string can be written in it, as a member's style is, and otherwise the string is written as it would be without it (YamlWriterOptions.DefaultScalarStyle). It reaches every value written as a YAML string: dates, times, GUIDs, URIs, versions, chars, enum names and Base64 take a single- or double-quoted default. A dictionary's string keys take it too, as YamlDotNet's do, and member names do not; numbers, booleans and nulls are not styled. A source-generated context takes its metadata path while it is set, since its generated dictionary handlers write keys out of the option's reach. Ignored in JSON-compatible style.
public YamlScalarStyle DefaultScalarStyle { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is not a scalar style. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
DictionaryKeyPolicyLink to this heading
Specifies the policy used to convert a IDictionary key's name to another format, such as camel-casing.
public YamlNamingPolicy? DictionaryKeyPolicy { get; set; }
This property can be set to YamlNamingPolicy.CamelCase to specify a camel-casing policy. It is not used when deserializing.
DisallowImplicitCollectionKeysLink to this heading
Gets or sets whether a flow collection may not be an implicit mapping key when reading (YamlReaderOptions.DisallowImplicitCollectionKeys). false by default. Set it to true so that a stream of YAML, for example with DeserializeAsyncEnumerable, yields each element as soon as it is complete rather than once its line, or 1024 characters, is known.
public bool DisallowImplicitCollectionKeys { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
DuplicateKeyHandlingLink to this heading
Gets or sets what deserialization does with a mapping key that appears twice (YamlDuplicateKeyHandling). By default, YamlDuplicateKeyHandling.Error, as YAML 1.2 requires. A repeated key that no member maps, or one inside a value that is skipped, is not judged.
public YamlDuplicateKeyHandling DuplicateKeyHandling { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is not a defined YamlDuplicateKeyHandling. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
EncoderLink to this heading
The encoder to use when escaping strings, or null to use the default encoder.
public JavaScriptEncoder? Encoder { get; set; }
ExpandSequenceItemsLink to this heading
Gets or sets, in block style, whether a collection that is a sequence item starts on the line after its dash (YamlWriterOptions.ExpandSequenceItems). Ignored in JSON-compatible style.
public bool ExpandSequenceItems { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
IgnoreReadOnlyFieldsLink to this heading
Determines whether read-only fields are ignored during serialization. A field is read-only if it is marked with the readonly keyword. The default value is false.
public bool IgnoreReadOnlyFields { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
Read-only fields are not deserialized regardless of this setting.
IgnoreReadOnlyPropertiesLink to this heading
Determines whether read-only properties are ignored during serialization. A property is read-only if it contains a public getter but not a public setter. The default value is false.
public bool IgnoreReadOnlyProperties { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
Read-only properties are not deserialized regardless of this setting.
IgnoreSourceStylesLink to this heading
Gets or sets, in block style, whether a YamlDocument, a YamlElement or a YamlNode is written in these options' styles rather than its source's: collections in YamlSerializerOptions.WriteStyle, scalars and keys as a typed value of the same text would be written, with YamlSerializerOptions.DefaultScalarStyle and YamlSerializerOptions.MultiLineStringStyle applying. So a parsed YAML document is written as block YAML, as its typed graph would be. A converter's or a member's style, and a node's YamlObject.CollectionStyle or YamlArray.CollectionStyle set by the caller, still apply. Anchors and tags are kept. Off by default: a document keeps its source's styles, as both YamlDotNet's and SharpYaml's models keep them (YamlWriterOptions.IgnoreSourceStyles). Ignored in JSON-compatible style.
public bool IgnoreSourceStyles { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
IncludeFieldsLink to this heading
Determines whether fields are handled on serialization and deserialization. The default value is false.
public bool IncludeFields { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
IndentCharacterLink to this heading
Defines the indentation character being used when YamlSerializerOptions.WriteIndented is enabled. Defaults to the space character.
public char IndentCharacter { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | value contains an invalid character. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
Allowed characters are space and horizontal tab.
IndentSequencesLink to this heading
Gets or sets whether, in block style, a sequence under a key is indented (key:\n - a) rather than written at the key's column (key:\n- a, the default). Ignored in JSON-compatible style.
public bool IndentSequences { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
IndentSizeLink to this heading
Defines the indentation size being used when YamlSerializerOptions.WriteIndented is enabled. Defaults to two.
public int IndentSize { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | value is out of the allowed range. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
Allowed values are all integers between 0 and 127, included.
InferClosedTypePolymorphismLink to this heading
Gets or sets a value indicating whether polymorphic serialization metadata is inferred for types that the compiler has marked as closed type hierarchies.
public bool InferClosedTypePolymorphism { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
By default, it's set to false. When set to true, types that declare a closed set of derived types (and that do not specify an explicit YamlDerivedTypeAttribute list) are treated as polymorphic. Closed derived types are expanded recursively, and each terminal derived type is registered using its simple name, equivalent to the result of nameof, as its type discriminator. If a type declares one or more YamlDerivedTypeAttribute registrations, inference is skipped for that type and only the explicitly registered derived types are used. Polymorphism configuration declared on derived types applies to their respective contracts and does not affect inference for the base type.
IsReadOnlyLink to this heading
Specifies whether the current instance has been locked for user modification.
public bool IsReadOnly { get; }
A YamlSerializerOptions instance can be locked either if it has been passed to one of the YamlSerializer methods, has been associated with a YamlSerializerContext instance, or a user explicitly called the YamlSerializerOptions.MakeReadOnly methods on the instance. Read-only instances use caching when querying YamlConverter and YamlTypeInfo metadata.
MappingOrderLink to this heading
Gets or sets the order in which an object's members are written: YamlMappingOrder.Declaration (the default) or YamlMappingOrder.Sorted, by YamlPropertyOrderAttribute's order and then by the written name, ordinal, as SharpYaml's MappingOrder = Sorted. Extension data's entries follow the members, sorted among themselves; a type discriminator stays first. Dictionaries keep their own order. Reading is unaffected.
public YamlMappingOrder MappingOrder { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is not a defined YamlMappingOrder. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
MaxAliasExpansionLink to this heading
Gets or sets the most nodes that YAML aliases may copy in one deserialization. An alias to an object or a collection shares the instance read at its anchor and copies nothing; an alias read into a scalar, a value type, an Object member or a type the anchored instance does not fit reads the anchored node again, and those nodes count. Past the limit, a YamlException is thrown. The default, 0, allows 10,000 nodes, or as many as the bytes of the input read so far when that is more.
public int MaxAliasExpansion { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is negative. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
MaxDepthLink to this heading
Gets or sets the maximum depth allowed when serializing or deserializing YAML, with the default (i.e. 0) indicating a max depth of 64.
public int MaxDepth { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
| ArgumentOutOfRangeException | Thrown when the max depth is set to a negative value. |
Going past this depth will throw a .
MaxLineWidthLink to this heading
Gets or sets, in block style, the width past which scalars are folded at a space and flow collections continue on a new line; 0 (the default) means no folding (YamlWriterOptions.MaxLineWidth). Ignored in JSON-compatible style.
public int MaxLineWidth { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is negative. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
MultiLineStringStyleLink to this heading
Gets or sets, in block style, how a string with a line break is written: literal (the default, YamlScalarStyle.None or YamlScalarStyle.Literal), folded, or double-quoted (YamlScalarStyle.DoubleQuoted, the default before M5f), where a block scalar can hold it (YamlWriterOptions.MultiLineStringStyle). Ignored in JSON-compatible style.
public YamlScalarStyle MultiLineStringStyle { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is not one of those four. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
NewLineLink to this heading
Gets or sets the new line string to use when YamlSerializerOptions.WriteIndented is true. The default is the value of Environment.NewLine.
public string NewLine { get; set; }
| Exception | Condition |
|---|---|
| ArgumentNullException | Thrown when the new line string is null. |
| ArgumentOutOfRangeException | Thrown when the new line string is not \n or \r\n. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
NumberHandlingLink to this heading
Specifies how number types should be handled when serializing or deserializing.
public YamlNumberHandling NumberHandling { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
PreferredObjectCreationHandlingLink to this heading
Specifies preferred object creation handling for properties when deserializing YAML. When set to YamlObjectCreationHandling.Populate all properties which are capable of reusing the existing instance will be populated.
public YamlObjectCreationHandling PreferredObjectCreationHandling { get; set; }
Only property type is taken into consideration. For example if property is of type IEnumerable<T> but it is assigned List<T> it will not be populated because IEnumerable<T> is not capable of populating. Additionally value types require a setter to be populated.
PropertyNameCaseInsensitiveLink to this heading
Determines whether a property's name uses a case-insensitive comparison during deserialization. The default value is false.
public bool PropertyNameCaseInsensitive { get; set; }
There is a performance cost associated when the value is true.
PropertyNamingPolicyLink to this heading
Specifies the policy used to convert a property's name on an object to another format, such as camel-casing. The resulting property name is expected to match the YAML payload during deserialization, and will be used when writing the property name during serialization.
public YamlNamingPolicy? PropertyNamingPolicy { get; set; }
The policy is not used for properties that have a YamlPropertyNameAttribute applied. This property can be set to YamlNamingPolicy.CamelCase to specify a camel-casing policy.
QuoteForLenientReadersLink to this heading
Gets or sets, in block style, whether strings that some readers misread although no YAML standard resolves them, such as Ruby's Psych, are quoted too (YamlWriterOptions.QuoteForLenientReaders). Off by default. Ignored in JSON-compatible style.
public bool QuoteForLenientReaders { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
ReadCommentHandlingLink to this heading
Defines how the comments are handled during deserialization.
public YamlCommentHandling ReadCommentHandling { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
| ArgumentOutOfRangeException | Thrown when the comment handling enum is set to a value that is not supported (or not within the YamlCommentHandling enum range). |
By default (YamlCommentHandling.Disallow) # comments are skipped and // and /* */ are not comments, as in standard YAML. With YamlCommentHandling.Skip the JSON comments of a JSON payload are skipped too, as System.Text.Json skips them; see YamlCommentHandling for where they are read. YamlCommentHandling.Allow is not supported here.
ReferenceHandlerLink to this heading
Configures how object references are handled when reading and writing YAML.
public ReferenceHandler? ReferenceHandler { get; set; }
ResolveMergeKeysLink to this heading
Gets or sets whether a plain << key merges mappings into the mapping that holds it (the YAML 1.1 merge type, yaml.org/type/merge): its value is an alias, a mapping or a sequence of them, the mapping's own keys win over merged ones, and an earlier merged mapping wins over a later one. Off by default, so << is an ordinary key.
public bool ResolveMergeKeys { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
With a << anywhere in the input, the document is read from its rewritten text: positions in errors refer to that text; a syntax error surfaces from the rewrite's parse as a YamlReaderException with no path; and the raw text of every object member (a YamlElement) is the rewritten spelling (block style, double quotes), not the source's. DeserializeAsyncEnumerable refuses the option.
RespectNullableAnnotationsLink to this heading
Gets or sets a value that indicates whether nullability annotations should be respected during serialization and deserialization.
public bool RespectNullableAnnotations { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
Nullability annotations are resolved from the properties, fields and constructor parameters that are used by the serializer. This includes annotations stemming from attributes such as NotNullAttribute, MaybeNullAttribute, AllowNullAttribute and DisallowNullAttribute. Due to restrictions in how nullable reference types are represented at run time, this setting only governs nullability annotations of non-generic properties and fields. It cannot be used to enforce nullability annotations of root-level types or generic parameters. The default setting for this property can be toggled application-wide using the "System.Text.Yaml.Serialization.RespectNullableAnnotationsDefault" feature switch.
RespectRequiredConstructorParametersLink to this heading
Gets or sets a value that indicates whether non-optional constructor parameters should be specified during deserialization.
public bool RespectRequiredConstructorParameters { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
For historical reasons constructor-based deserialization treats all constructor parameters as optional by default. This flag allows users to toggle that behavior as necessary for each YamlSerializerOptions instance. The default setting for this property can be toggled application-wide using the "System.Text.Yaml.Serialization.RespectRequiredConstructorParametersDefault" feature switch.
SchemaLink to this heading
Gets or sets the schema that resolves plain scalars in value position when deserializing: YamlSchemaKind.Core (YAML 1.2, the default), YamlSchemaKind.Yaml11, YamlSchemaKind.Json or YamlSchemaKind.Failsafe. Under Json block output double-quotes every string value (and every date, time or GUID) it would otherwise write plain, so it reads back under the same schema (M7c); keys are unchanged, since the JSON schema reads plain keys, and a non-finite number (.nan, .inf) has no YAML-schema form and is refused on read. Under Failsafe writing does not change, and plain numbers and booleans read back as strings.
public YamlSchemaKind Schema { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is not a defined YamlSchemaKind. |
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
StrictLink to this heading
Gets a read-only, singleton instance of YamlSerializerOptions that uses the strict configuration.
public static YamlSerializerOptions Strict { get; }
Each YamlSerializerOptions instance encapsulates its own serialization metadata caches, so using fresh default instances every time one is needed can result in redundant recomputation of converters. This property provides a shared instance that can be consumed by any number of components without necessitating any converter recomputation.
TagMappingsLink to this heading
Gets the YAML tags that select a type when reading, and that the type writes, as YamlDotNet's WithTagMapping: an explicit allow-list. A tag never names a CLR type.
public IDictionary<string, Type> TagMappings { get; }
| Exception | Condition |
|---|---|
| InvalidOperationException | An entry is changed after serialization or deserialization has occurred. |
A key is a local tag (!dog) or a global tag URI (tag:example.com,2000:dog), compared with a node's expanded tag, so a %TAG handle and a verbatim tag select the same entry. Core tags (!!str), ! and ? are refused, as are a tag or a type mapped twice, and a type that cannot be created (open generic, abstract, an interface) or cannot be a runtime type (Nullable<T>).
Reading: at an Object site a mapped tag reads its type, scalars included (!celsius 21.5 mapped to Double); an unmapped tag keeps the YamlElement, with its tag. At a site of a reference type with no declared polymorphism, a mapped type it can hold is read; one it cannot hold is an error. A declared hierarchy decides at its own sites. The type comes from the options' type-info resolution, so a source-generated context must contain it.
Writing: one tag per type. A value whose runtime type is mapped is written with the tag where the declared type differs, so every boxed Double in an Object member is written !celsius … with the entry above; a boxed double? is a Double. A mapped type with a custom converter gets the tag before whatever node the converter writes. The JSON-compatible writer cannot write a tag: it writes a mapped value untagged, so it reads back as an element at an Object site.
Setting entries on options that use a source-generated context turns its serialization fast path off.
TypeClassifiersLink to this heading
Gets the list of custom type classifier factories.
public IList<YamlTypeClassifierFactory> TypeClassifiers { get; }
Each YamlTypeClassifierFactory in the list is consulted (in declaration order) when configuring a union or polymorphic type for which no per-type classifier was set via YamlUnionAttribute.TypeClassifier or YamlPolymorphicAttribute.TypeClassifier. The first factory whose YamlTypeClassifierFactory.CanClassify returns true is used; otherwise the built-in type resolution for that metadata shape applies.
Once serialization or deserialization occurs, the list cannot be modified.
TypeInfoResolverLink to this heading
Gets or sets the YamlTypeInfo contract resolver used by this instance.
public IYamlTypeInfoResolver? TypeInfoResolver { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
A null setting is equivalent to using the reflection-based DefaultYamlTypeInfoResolver. The property will be populated automatically once used with one of the YamlSerializer methods. This property is kept in sync with the YamlSerializerOptions.TypeInfoResolverChain property. Any change made to this property will be reflected by YamlSerializerOptions.TypeInfoResolverChain and vice versa.
TypeInfoResolverChainLink to this heading
Gets the list of chained YamlTypeInfo contract resolvers used by this instance.
public IList<IYamlTypeInfoResolver> TypeInfoResolverChain { get; }
The ordering of the chain is significant: YamlSerializerOptions will query each of the resolvers in their specified order, returning the first result that is non-null. If all resolvers in the chain return null, then YamlSerializerOptions will also return null. This property is auxiliary to and is kept in sync with the YamlSerializerOptions.TypeInfoResolver property. Any change made to this property will be reflected by YamlSerializerOptions.TypeInfoResolver and vice versa.
UnknownTypeHandlingLink to this heading
Defines how deserializing a type declared as an Object is handled during deserialization.
public YamlUnknownTypeHandling UnknownTypeHandling { get; set; }
UnmappedMemberHandlingLink to this heading
Determines how YamlSerializer handles YAML properties that cannot be mapped to a specific .NET member when deserializing object types.
public YamlUnmappedMemberHandling UnmappedMemberHandling { get; set; }
WebLink to this heading
Gets a read-only, singleton instance of YamlSerializerOptions that uses the web configuration.
public static YamlSerializerOptions Web { get; }
Each YamlSerializerOptions instance encapsulates its own serialization metadata caches, so using fresh default instances every time one is needed can result in redundant recomputation of converters. This property provides a shared instance that can be consumed by any number of components without necessitating any converter recomputation.
WriteIndentedLink to this heading
Defines whether YAML should pretty print which includes: indenting nested YAML tokens, adding new lines, and adding white space between property names and values. By default, the YAML is serialized without any extra white space.
public bool WriteIndented { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
WriteStyleLink to this heading
Gets or sets the output style of serialization: YamlWriterStyle.Block YAML, or YamlWriterStyle.JsonCompatible JSON. When it is not set, the output is block YAML.
public YamlWriterStyle WriteStyle { get; set; }
| Exception | Condition |
|---|---|
| InvalidOperationException | Thrown if this property is set after serialization or deserialization has occurred. |
MethodsLink to this heading
GetConverterLink to this heading
Returns the converter for the specified type.
public YamlConverter GetConverter(Type typeToConvert);
Parameters
typeToConvert: The type to return a converter for.
Returns: The converter for the given type.
| Exception | Condition |
|---|---|
| InvalidOperationException | The configured YamlConverter for typeToConvert returned an invalid converter. |
| NotSupportedException | There is no compatible YamlConverter for typeToConvert or its serializable members. |
GetTypeInfoLink to this heading
Gets the YamlTypeInfo contract metadata resolved by the current YamlSerializerOptions instance.
public YamlTypeInfo GetTypeInfo(Type type);
Parameters
type: The type to resolve contract metadata for.
Returns: The contract metadata resolved for type.
| Exception | Condition |
|---|---|
| ArgumentNullException | type is null. |
| ArgumentException | type is not valid for serialization. |
Returned metadata can be downcast to YamlTypeInfo<T> and used with the relevant YamlSerializer overloads. If the YamlSerializerOptions instance is locked for modification, the method will return a cached instance for the metadata.
Gets the YamlTypeInfo<T> contract metadata resolved by the current YamlSerializerOptions instance.
public YamlTypeInfo<T?> GetTypeInfo<T>();
Type parameters
T: The type to resolve contract metadata for.
Returns: The contract metadata resolved for T.
| Exception | Condition |
|---|---|
| ArgumentException | T is not valid for serialization. |
If the YamlSerializerOptions instance is locked for modification, the method will return a cached instance for the metadata.
MakeReadOnlyLink to this heading
Marks the current instance as read-only preventing any further user modification.
public void MakeReadOnly();
| Exception | Condition |
|---|---|
| InvalidOperationException | The instance does not specify a YamlSerializerOptions.TypeInfoResolver setting. |
This method is idempotent.
Marks the current instance as read-only preventing any further user modification.
public void MakeReadOnly(bool populateMissingResolver);
Parameters
populateMissingResolver: Populates unconfiguredYamlSerializerOptions.TypeInfoResolverproperties with the reflection-based default.
| Exception | Condition |
|---|---|
| InvalidOperationException | The instance does not specify a YamlSerializerOptions.TypeInfoResolver setting. Thrown if populateMissingResolver is false. -OR- The YamlSerializer.IsReflectionEnabledByDefault feature switch has been turned off. |
When populateMissingResolver is set to true, configures the instance following the semantics of the YamlSerializer methods accepting YamlSerializerOptions parameters. This method is idempotent.
TryGetTypeInfoLink to this heading
Tries to get the YamlTypeInfo contract metadata resolved by the current YamlSerializerOptions instance.
public bool TryGetTypeInfo(Type type, out YamlTypeInfo? typeInfo);
Parameters
type: The type to resolve contract metadata for.typeInfo: The resolved contract metadata, ornullif not contract could be resolved.
Returns: true if a contract for type was found, or false otherwise.
| Exception | Condition |
|---|---|
| ArgumentNullException | type is null. |
| ArgumentException | type is not valid for serialization. |
Returned metadata can be downcast to YamlTypeInfo<T> and used with the relevant YamlSerializer overloads. If the YamlSerializerOptions instance is locked for modification, the method will return a cached instance for the metadata.
Tries to get the YamlTypeInfo<T> contract metadata resolved by the current YamlSerializerOptions instance.
public bool TryGetTypeInfo<T>(out YamlTypeInfo<T>? typeInfo);
Type parameters
T: The type to resolve contract metadata for.
Parameters
typeInfo: The resolved contract metadata, ornullif no contract could be resolved.
Returns: true if a contract for T was found, or false otherwise.
| Exception | Condition |
|---|---|
| ArgumentException | T is not valid for serialization. |
If the YamlSerializerOptions instance is locked for modification, the method will return a cached instance for the metadata.