ReferenceHandler class

This class defines how the YamlSerializer deals with references on serialization and deserialization.

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

public abstract class ReferenceHandler

Derived: ReferenceHandler<T>

This class defines how the YamlSerializer deals with references on serialization and deserialization.

ConstructorsLink to this heading

protected ReferenceHandler();

PropertiesLink to this heading

IgnoreCyclesLink to this heading

Ignores an object when a reference cycle is detected during serialization.

public static ReferenceHandler IgnoreCycles { get; }

PreserveLink to this heading

Metadata properties will be honored when deserializing YAML objects and arrays into reference types and written when serializing reference types. This is necessary to create round-trippable YAML from objects that contain cycles or duplicate references.

public static ReferenceHandler Preserve { get; }

In YAML block style (M5b), an object or collection referenced more than once is written once with an anchor (&1), and each later reference as an alias (*1); a first pass over the graph finds the repeated objects. ReferenceHandler.PreserveAll anchors every object instead. On read, aliases are read with any handler; with this one, an alias inside the node it refers to builds the reference cycle. The $id/$ref description below is the JSON-compatible style's output, which both handlers also read in any style. * On Serialize: When writing complex reference types, the serializer also writes metadata properties (`$id`, `$values`, and `$ref`) within them. The output YAML will contain an extra `$id` property for every object, and for every enumerable type the YAML array emitted will be nested within a YAML object containing an `$id` and `$values` property. Object.ReferenceEquals is used to determine whether objects are identical. When an object is identical to a previously serialized one, a pointer (`$ref`) to the identifier (`$id`) of such object is written instead. No metadata properties are written for value types. * On Deserialize: The metadata properties within the YAML that are used to preserve duplicated references and cycles will be honored as long as they are well-formed**. For YAML objects that don't contain any metadata properties, the deserialization behavior is identical to null. For value types: * The `$id` metadata property is ignored. * A YamlException is thrown if a `$ref` metadata property is found within the YAML object. * For enumerable value types, the `$values` metadata property is ignored. ** For the metadata properties within the YAML to be considered well-formed, they must follow these rules: 1) The `$id` metadata property must be the first property in the YAML object. 2) A YAML object that contains a `$ref` metadata property must not contain any other properties. 3) The value of the `$ref` metadata property must refer to an `$id` that has appeared earlier in the YAML. 4) The value of the `$id` and `$ref` metadata properties must be a YAML string. 5) For enumerable types, such as List<T>, the YAML array must be nested within a YAML object containing an `$id` and `$values` metadata property, in that order. 6) For enumerable types, the `$values` metadata property must be a YAML array. 7) The `$values` metadata property is only valid when referring to enumerable types. If the YAML is not well-formed, a YamlException is thrown.

PreserveAllLink to this heading

Writes YAML anchors and aliases for every object and collection, the root included, in one pass, and reads aliases and System.Text.Json's reference metadata as ReferenceHandler.Preserve does.

public static ReferenceHandler PreserveAll { get; }

ReferenceHandler.Preserve anchors only the objects referenced more than once, after a first pass over the graph. In the JSON-compatible style, which has no anchors, both write $id, $ref and $values for every object, as System.Text.Json does.

MethodsLink to this heading

CreateResolverLink to this heading

Returns the ReferenceResolver used for each serialization call.

public abstract ReferenceResolver CreateResolver();

Returns: The resolver to use for serialization and deserialization.

Generated from the XML documentation of the libraryBuilt with Douze

Esc to close