YamlPropertyInfo class

Provides YAML serialization-related metadata about a property or field defined in an object.

Namespace: System.Text.Yaml.Serialization.Metadata ยท Assembly: Styml.dll

public abstract class YamlPropertyInfo

Provides YAML serialization-related metadata about a property or field defined in an object.

PropertiesLink to this heading

AssociatedParameterLink to this heading

Gets the constructor parameter associated with the current property.

public YamlParameterInfo? AssociatedParameter { get; }

Returns the YamlParameterInfo metadata for the parameter in the deserialization constructor that has been associated with the current property. A constructor parameter is matched to a property or field if they are of the same type and have the same name, up to case insensitivity. Each constructor parameter must be matched to exactly one property of field.

AttributeProviderLink to this heading

Gets or sets a custom attribute provider for the current property.

public ICustomAttributeProvider? AttributeProvider { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

When resolving metadata via the built-in resolvers this will be populated with the underlying MemberInfo of the serialized property or field. Setting a custom attribute provider will have no impact on the contract model, but serves as metadata for downstream contract modifiers.

CommentLink to this heading

Gets or sets the comment written above the property in block style: one # line per line, at the key's indentation. Written for a null value too, and not when an ignore condition leaves the property out; dropped in JSON-compatible style.

public string? Comment { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

For contracts originating from DefaultYamlTypeInfoResolver or YamlSerializerContext, the value of this property will be mapped from YamlCommentAttribute annotations. The text holds printable characters and tabs, its lines separated by CR, LF or CRLF; anything else is an InvalidOperationException when the contract is configured.

CustomConverterLink to this heading

Gets or sets a custom converter override for the current property.

public YamlConverter? CustomConverter { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

It is possible to use YamlConverterFactory instances with this property. For contracts originating from DefaultYamlTypeInfoResolver, the value of YamlPropertyInfo.CustomConverter will be mapped from YamlConverterAttribute annotations.

DeclaringTypeLink to this heading

Gets the declaring type of the property.

public Type DeclaringType { get; }

GetLink to this heading

Gets or sets a getter delegate for the property.

public Func<object, object?>? Get { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

Setting to null will result in the property being skipped on serialization.

IsExtensionDataLink to this heading

Specifies whether the current property is a special extension data property.

public bool IsExtensionData { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification. -or- The current YamlPropertyInfo.PropertyType is not valid for use with extension data.

For contracts originating from DefaultYamlTypeInfoResolver or YamlSerializerContext, the value of this property will be mapped from YamlExtensionDataAttribute annotations.

IsGetNullableLink to this heading

Gets or sets a value indicating whether the return type of the getter is annotated as nullable.

public bool IsGetNullable { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification. -or- The current YamlPropertyInfo.PropertyType is not a reference type or Nullable<T>.

Contracts originating from DefaultYamlTypeInfoResolver or YamlSerializerContext, derive the value of this property from nullable reference type annotations, including annotations from attributes such as NotNullAttribute or MaybeNullAttribute. This property has no effect on serialization unless the YamlSerializerOptions.RespectNullableAnnotations property has been enabled, in which case the serializer will reject any null values returned by the getter.

IsRequiredLink to this heading

Specifies whether the current property is required for deserialization to be successful.

public bool IsRequired { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

For contracts originating from DefaultYamlTypeInfoResolver or YamlSerializerContext, the value of this property will be mapped from YamlRequiredAttribute annotations. For contracts using DefaultYamlTypeInfoResolver, properties using the required keyword will also map to this setting, unless deserialization uses a SetsRequiredMembersAttribute on a constructor that populates all required properties. required keyword is currently not supported in YamlSerializerContext contracts.

IsSetNullableLink to this heading

Gets or sets a value indicating whether the input type of the setter is annotated as nullable.

public bool IsSetNullable { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification. -or- The current YamlPropertyInfo.PropertyType is not a reference type or Nullable<T>.

Contracts originating from DefaultYamlTypeInfoResolver or YamlSerializerContext, derive the value of this property from nullable reference type annotations, including annotations from attributes such as AllowNullAttribute or DisallowNullAttribute. This property has no effect on deserialization unless the YamlSerializerOptions.RespectNullableAnnotations property has been enabled, in which case the serializer will reject any null deserialization results. If the property has been associated with a deserialization constructor parameter, this setting reflected the nullability annotation of the parameter and not the property setter.

NameLink to this heading

Gets or sets the YAML property name used when serializing the property.

public string Name { get; set; }
Exception Condition
ArgumentNullException value is null.
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

The value of YamlPropertyInfo.Name cannot conflict with that of other YamlPropertyInfo defined in the declaring YamlPropertyInfo.YamlTypeInfo. For contracts originating from DefaultYamlTypeInfoResolver or YamlSerializerContext, the value typically reflects the underlying .NET member name, the name derived from YamlSerializerOptions.PropertyNamingPolicy, or the value specified in YamlPropertyNameAttribute.

NumberHandlingLink to this heading

Gets or sets the YamlNumberHandling applied to the current property.

public YamlNumberHandling? NumberHandling { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

For contracts originating from DefaultYamlTypeInfoResolver or YamlSerializerContext, the value of this property will be mapped from YamlNumberHandlingAttribute annotations.

ObjectCreationHandlingLink to this heading

Gets or sets a value indicating if the property or field should be replaced or populated during deserialization.

public YamlObjectCreationHandling? ObjectCreationHandling { get; set; }

Initial value for this property is based on the presence of YamlObjectCreationHandlingAttribute attribute on the property. When null effective handling will be resolved based on capability of property converter to populate, containing type's YamlTypeInfo.PreferredPropertyObjectCreationHandling. and YamlSerializerOptions.PreferredObjectCreationHandling value.

OptionsLink to this heading

Gets the YamlSerializerOptions value associated with the current contract instance.

public YamlSerializerOptions Options { get; }

OrderLink to this heading

Gets or sets the serialization order for the current property.

public int Order { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

For contracts originating from DefaultYamlTypeInfoResolver or YamlSerializerContext, the value of this property will be mapped from YamlPropertyOrderAttribute annotations.

PropertyTypeLink to this heading

Gets the type of the current property.

public Type PropertyType { get; }

ScalarStyleLink to this heading

Gets or sets the scalar style of the property's string value in block style; YamlScalarStyle.None (the default) lets the writer choose.

public YamlScalarStyle ScalarStyle { get; set; }
Exception Condition
ArgumentOutOfRangeException The value is not a YamlScalarStyle.
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

For contracts originating from DefaultYamlTypeInfoResolver or YamlSerializerContext, the value of this property will be mapped from YamlScalarStyleAttribute annotations. The style applies where it holds the value and reads back as the same string; otherwise the writer's default choice is written. It does not reach numbers, booleans, nulls, a collection's items, nested objects or keys.

SetLink to this heading

Gets or sets a setter delegate for the property.

public Action<object, object?>? Set { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

Setting to null will result in the property being skipped on deserialization.

ShouldSerializeLink to this heading

Gets or sets a predicate deciding whether the current property value should be serialized.

public Func<object, object?, bool>? ShouldSerialize { get; set; }
Exception Condition
InvalidOperationException The YamlPropertyInfo instance has been locked for further modification.

The first parameter denotes the parent object, the second parameter denotes the property value. Setting the predicate to null is equivalent to always serializing the property value. For contracts originating from DefaultYamlTypeInfoResolver, the value of YamlIgnoreAttribute.Condition will map to this predicate.

Generated from the XML documentation of the libraryBuilt with Douze

Esc to close