Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

YamlSerializer

OfficeIMO.Yaml

Namespace
OfficeIMO.Yaml
Assembly
OfficeIMO.Yaml
Source revision
0eef6a5756b9 with working tree changes
Modifiers
static

Converts between .NET objects and YAML, through YamlReader and YamlWriter directly. The API follows System.Text.Json: overloads with YamlSerializerOptions create metadata by reflection when no YamlSerializerOptions.TypeInfoResolver is set, and overloads with YamlTypeInfo<T> or a YamlSerializerContext use generated metadata, for trimmed and NativeAOT applications.

Inheritance

  • object
  • YamlSerializer

Remarks

Reading resolves aliases within : an alias read as returns the value read for its anchor (see ), and a typed alias is read again from its anchored node. << merge keys apply. Values that do not fit their type fail with a whose is and whose position points at the node. Tags never select a .NET type: only discriminators registered with do. Text, stream and text-reader input must hold at most one document; read a multi-document stream with a , one call per document.

Methods

Deserialize 10 overloads
public static object? Deserialize(string yaml, Type returnType, YamlSerializerOptions? options = null) #

Reads a YAML document as returnType.

Parameters

yaml string required
returnType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

object?
public static object? Deserialize(Stream utf8Yaml, Type returnType, YamlSerializerOptions? options = null) #

Reads a YAML document from a stream as returnType. The stream stays open.

Parameters

utf8Yaml System.IO.Stream required
returnType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

object?
public static object? Deserialize(TextReader reader, Type returnType, YamlSerializerOptions? options = null) #

Reads a YAML document from a text reader as returnType. The reader stays open.

Parameters

reader System.IO.TextReader required
returnType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

object?
public static object? Deserialize(YamlReader reader, Type returnType, YamlSerializerOptions? options = null) #

Reads one value from a YamlReader as returnType, as YamlSerializer.Deserialize does.

Parameters

reader OfficeIMO.Yaml.YamlReader required
returnType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

object?
public static object? Deserialize(YamlNode node, Type returnType, YamlSerializerOptions? options = null) #

Reads a model node as returnType.

Parameters

node OfficeIMO.Yaml.YamlNode required
returnType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

object?
public static object? Deserialize(string yaml, Type returnType, YamlSerializerContext context) #

Reads a YAML document as returnType with the context's metadata.

Parameters

yaml string required
returnType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required

Returns

object?
public static object? Deserialize(Stream utf8Yaml, Type returnType, YamlSerializerContext context) #

Reads a YAML document from a stream as returnType with the context's metadata. The stream stays open.

Parameters

utf8Yaml System.IO.Stream required
returnType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required

Returns

object?
public static object? Deserialize(TextReader reader, Type returnType, YamlSerializerContext context) #

Reads a YAML document from a text reader as returnType with the context's metadata. The reader stays open.

Parameters

reader System.IO.TextReader required
returnType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required

Returns

object?
public static object? Deserialize(YamlReader reader, Type returnType, YamlSerializerContext context) #

Reads one value from a YamlReader as returnType with the context's metadata.

Parameters

reader OfficeIMO.Yaml.YamlReader required
returnType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required

Returns

object?
public static object? Deserialize(YamlNode node, Type returnType, YamlSerializerContext context) #

Reads a model node as returnType with the context's metadata.

Parameters

node OfficeIMO.Yaml.YamlNode required
returnType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required

Returns

object?
Deserialize``1 10 overloads
public static T? Deserialize<T>(string yaml, YamlSerializerOptions? options = null) #

Reads a YAML document as T. Empty input reads as null.

Type Parameters

T

Parameters

yaml string required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

T?

Exceptions

  • YamlException – The input is malformed, exceeds a limit or does not fit T.
public static T? Deserialize<T>(Stream utf8Yaml, YamlSerializerOptions? options = null) #

Reads a YAML document from a stream as T; the encoding is detected. The stream stays open.

Type Parameters

T

Parameters

utf8Yaml System.IO.Stream required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

T?
public static T? Deserialize<T>(TextReader reader, YamlSerializerOptions? options = null) #

Reads a YAML document from a text reader as T. The reader stays open.

Type Parameters

T

Parameters

reader System.IO.TextReader required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

T?
public static T? Deserialize<T>(YamlReader reader, YamlSerializerOptions? options = null) #

Reads one value from a YamlReader. Between documents it reads the next document's root and stops on that document's end event, returning null at the end of the stream; on a node event it reads that node and stops on its last event. The reader's settings and limits apply.

Type Parameters

T

Parameters

reader OfficeIMO.Yaml.YamlReader required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

T?
public static T? Deserialize<T>(YamlNode node, YamlSerializerOptions? options = null) #

Reads a model node, such as a section of a loaded YamlDocument, as T.

Type Parameters

T

Parameters

node OfficeIMO.Yaml.YamlNode required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

T?
public static T? Deserialize<T>(string yaml, YamlTypeInfo<T?> typeInfo) #

Reads a YAML document with generated metadata. Empty input reads as null.

Type Parameters

T

Parameters

yaml string required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required

Returns

T?

Exceptions

  • YamlException – The input is malformed, exceeds a limit or does not fit the type.
public static T? Deserialize<T>(Stream utf8Yaml, YamlTypeInfo<T?> typeInfo) #

Reads a YAML document from a stream with generated metadata; the encoding is detected. The stream stays open.

Type Parameters

T

Parameters

utf8Yaml System.IO.Stream required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required

Returns

T?
public static T? Deserialize<T>(TextReader reader, YamlTypeInfo<T?> typeInfo) #

Reads a YAML document from a text reader with generated metadata. The reader stays open.

Type Parameters

T

Parameters

reader System.IO.TextReader required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required

Returns

T?
public static T? Deserialize<T>(YamlReader reader, YamlTypeInfo<T?> typeInfo) #

Reads one value from a YamlReader with generated metadata, as YamlSerializer.Deserialize does.

Type Parameters

T

Parameters

reader OfficeIMO.Yaml.YamlReader required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required

Returns

T?
public static T? Deserialize<T>(YamlNode node, YamlTypeInfo<T?> typeInfo) #

Reads a model node with generated metadata.

Type Parameters

T

Parameters

node OfficeIMO.Yaml.YamlNode required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required

Returns

T?
Serialize 8 overloads
public static string Serialize(object? value, Type inputType, YamlSerializerOptions? options = null) #

Writes value as inputType and returns the text.

Parameters

value object? required
inputType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

string
public static void Serialize(Stream utf8Yaml, object? value, Type inputType, YamlSerializerOptions? options = null) #

Writes value as inputType to a UTF-8 stream, which stays open.

Parameters

utf8Yaml System.IO.Stream required
value object? required
inputType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional
public static void Serialize(TextWriter writer, object? value, Type inputType, YamlSerializerOptions? options = null) #

Writes value as inputType to a text writer, which stays open.

Parameters

writer System.IO.TextWriter required
value object? required
inputType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional
public static void Serialize(YamlWriter writer, object? value, Type inputType, YamlSerializerOptions? options = null) #

Writes value as inputType, as one node at the writer's position.

Parameters

writer OfficeIMO.Yaml.YamlWriter required
value object? required
inputType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional
public static string Serialize(object? value, Type inputType, YamlSerializerContext context) #

Writes value as inputType with the context's metadata and returns the text.

Parameters

value object? required
inputType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required

Returns

string
public static void Serialize(Stream utf8Yaml, object? value, Type inputType, YamlSerializerContext context) #

Writes value as inputType with the context's metadata to a UTF-8 stream, which stays open.

Parameters

utf8Yaml System.IO.Stream required
value object? required
inputType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required
public static void Serialize(TextWriter writer, object? value, Type inputType, YamlSerializerContext context) #

Writes value as inputType with the context's metadata to a text writer, which stays open.

Parameters

writer System.IO.TextWriter required
value object? required
inputType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required
public static void Serialize(YamlWriter writer, object? value, Type inputType, YamlSerializerContext context) #

Writes value as inputType with the context's metadata, as one node at the writer's position.

Parameters

writer OfficeIMO.Yaml.YamlWriter required
value object? required
inputType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required
SerializeToNode 2 overloads
public static YamlNode SerializeToNode(object? value, Type inputType, YamlSerializerOptions? options = null) #

Converts value as inputType to a detached YamlNode tree.

Parameters

value object? required
inputType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

YamlNode
public static YamlNode SerializeToNode(object? value, Type inputType, YamlSerializerContext context) #

Converts value as inputType with the context's metadata to a detached YamlNode tree.

Parameters

value object? required
inputType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required

Returns

YamlNode
SerializeToNode``1 2 overloads
public static YamlNode SerializeToNode<T>(T? value, YamlSerializerOptions? options = null) #

Converts value to a detached YamlNode tree, to insert into a YamlDocument next to hand-edited content.

Type Parameters

T

Parameters

value T? required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

YamlNode
public static YamlNode SerializeToNode<T>(T? value, YamlTypeInfo<T?> typeInfo) #

Converts value with generated metadata to a detached YamlNode tree.

Type Parameters

T

Parameters

value T? required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required

Returns

YamlNode
SerializeToUtf8Bytes 2 overloads
public static byte[] SerializeToUtf8Bytes(object? value, Type inputType, YamlSerializerOptions? options = null) #

Writes value as inputType and returns its UTF-8 bytes.

Parameters

value object? required
inputType System.Type required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

byte[]
public static byte[] SerializeToUtf8Bytes(object? value, Type inputType, YamlSerializerContext context) #

Writes value as inputType with the context's metadata and returns its UTF-8 bytes.

Parameters

value object? required
inputType System.Type required
context OfficeIMO.Yaml.YamlSerializerContext required

Returns

byte[]
SerializeToUtf8Bytes``1 2 overloads
public static byte[] SerializeToUtf8Bytes<T>(T? value, YamlSerializerOptions? options = null) #

Writes value as a YAML document and returns its UTF-8 bytes, without a byte-order mark.

Type Parameters

T

Parameters

value T? required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

byte[]
public static byte[] SerializeToUtf8Bytes<T>(T? value, YamlTypeInfo<T?> typeInfo) #

Writes value with generated metadata and returns its UTF-8 bytes, without a byte-order mark.

Type Parameters

T

Parameters

value T? required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required

Returns

byte[]
Serialize``1 8 overloads
public static string Serialize<T>(T? value, YamlSerializerOptions? options = null) #

Writes value as a YAML document and returns the text.

Type Parameters

T

Parameters

value T? required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional

Returns

string
public static void Serialize<T>(Stream utf8Yaml, T? value, YamlSerializerOptions? options = null) #

Writes value as a UTF-8 YAML document to utf8Yaml, which stays open.

Type Parameters

T

Parameters

utf8Yaml System.IO.Stream required
value T? required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional
public static void Serialize<T>(TextWriter writer, T? value, YamlSerializerOptions? options = null) #

Writes value as a YAML document to writer, which stays open.

Type Parameters

T

Parameters

writer System.IO.TextWriter required
value T? required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional
public static void Serialize<T>(YamlWriter writer, T? value, YamlSerializerOptions? options = null) #

Writes value as one node at the writer's position: a document root, a mapping value or a sequence item. The writer's own layout settings apply.

Type Parameters

T

Parameters

writer OfficeIMO.Yaml.YamlWriter required
value T? required
options OfficeIMO.Yaml.YamlSerializerOptions? = null optional
public static string Serialize<T>(T? value, YamlTypeInfo<T?> typeInfo) #

Writes value with generated metadata and returns the text.

Type Parameters

T

Parameters

value T? required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required

Returns

string
public static void Serialize<T>(Stream utf8Yaml, T? value, YamlTypeInfo<T?> typeInfo) #

Writes value with generated metadata to a UTF-8 stream, which stays open.

Type Parameters

T

Parameters

utf8Yaml System.IO.Stream required
value T? required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required
public static void Serialize<T>(TextWriter writer, T? value, YamlTypeInfo<T?> typeInfo) #

Writes value with generated metadata to a text writer, which stays open.

Type Parameters

T

Parameters

writer System.IO.TextWriter required
value T? required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required
public static void Serialize<T>(YamlWriter writer, T? value, YamlTypeInfo<T?> typeInfo) #

Writes value with generated metadata, as one node at the writer's position.

Type Parameters

T

Parameters

writer OfficeIMO.Yaml.YamlWriter required
value T? required
typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?> required