YamlSerializer
OfficeIMO.Yaml
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
public static object? Deserialize(string yaml, Type returnType, YamlSerializerOptions? options = null) #Reads a YAML document as returnType.
Parameters
- yaml string
- returnType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- returnType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- returnType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- returnType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
Returns
object?public static object? Deserialize(YamlNode node, Type returnType, YamlSerializerOptions? options = null) #Reads a model node as returnType.
Parameters
- node OfficeIMO.Yaml.YamlNode
- returnType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- returnType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
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
- returnType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
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
- returnType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
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
- returnType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
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
- returnType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
Returns
object?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
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>
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
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>
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
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>
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
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>
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
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>
Returns
T?public static string Serialize(object? value, Type inputType, YamlSerializerOptions? options = null) #Writes value as inputType and returns the text.
Parameters
- value object?
- inputType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
Returns
stringpublic 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
- value object?
- inputType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- value object?
- inputType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- value object?
- inputType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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?
- inputType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
Returns
stringpublic 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
- value object?
- inputType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
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
- value object?
- inputType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
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
- value object?
- inputType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
public static YamlNode SerializeToNode(object? value, Type inputType, YamlSerializerOptions? options = null) #Converts value as inputType to a detached YamlNode tree.
Parameters
- value object?
- inputType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
Returns
YamlNodepublic 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?
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
Returns
YamlNodepublic static byte[] SerializeToUtf8Bytes(object? value, Type inputType, YamlSerializerOptions? options = null) #Writes value as inputType and returns its UTF-8 bytes.
Parameters
- value object?
- inputType System.Type
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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?
- inputType System.Type
- context OfficeIMO.Yaml.YamlSerializerContext
Returns
byte[]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?
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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?
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>
Returns
byte[]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?
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
Returns
stringpublic 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
- value T?
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- value T?
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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
- value T?
- options OfficeIMO.Yaml.YamlSerializerOptions? = null
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?
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>
Returns
stringpublic 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
- value T?
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>
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
- value T?
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>
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
- value T?
- typeInfo OfficeIMO.Yaml.YamlTypeInfo<T?>