YamlSerializer Class

Serializes and deserializes YAML payloads, following a System.Text.Json-style API shape.

public static class YamlSerializer

Properties

NameDescription
IsReflectionEnabledByDefaultGets a value indicating whether reflection-based serialization is enabled by default.

IsReflectionEnabledByDefault

YamlSerializer.cs

Gets a value indicating whether reflection-based serialization is enabled by default.

public static bool IsReflectionEnabledByDefault { get; }

Property value

bool

Methods

NameDescription
Deserialize(Stream, YamlTypeInfo)Deserializes a payload from a stream using UTF-8 encoding and explicit type metadata.
Deserialize(Stream, Type, YamlSerializerContext)Deserializes YAML from a stream using UTF-8 encoding and generated metadata from a serializer context.
Deserialize(Stream, Type, YamlSerializerOptions?)Deserializes YAML from a stream using UTF-8 encoding.
Deserialize(TextReader, YamlTypeInfo)Deserializes a payload from a text reader using explicit type metadata.
Deserialize(TextReader, Type, YamlSerializerContext)Deserializes YAML from a text reader using an explicit destination type and generated metadata from a serializer context.
Deserialize(TextReader, Type, YamlSerializerOptions?)Deserializes YAML from a text reader using an explicit destination type.
Deserialize(string, YamlTypeInfo)Deserializes a payload using explicit type metadata.
Deserialize(string, Type, YamlSerializerContext)Deserializes a YAML payload into an explicit destination type using generated metadata from a serializer context.
Deserialize(string, Type, YamlSerializerOptions?)Deserializes a YAML payload into an explicit destination type.
Deserialize<T>(Stream, YamlSerializerContext)Deserializes YAML from a stream using UTF-8 encoding and generated metadata from a serializer context.
Deserialize<T>(Stream, YamlSerializerOptions?)Deserializes YAML from a stream using UTF-8 encoding.
Deserialize<T>(Stream, YamlTypeInfo<T>)Deserializes a payload from a stream using UTF-8 encoding and explicit type metadata.
Deserialize<T>(TextReader, YamlSerializerContext)Deserializes YAML from a text reader using generated metadata from a serializer context.
Deserialize<T>(TextReader, YamlSerializerOptions?)Deserializes YAML from a text reader.
Deserialize<T>(TextReader, YamlTypeInfo<T>)Deserializes a payload from a text reader using explicit type metadata.
Deserialize<T>(string, YamlSerializerContext)Deserializes a YAML payload from text using generated metadata from a serializer context.
Deserialize<T>(string, YamlSerializerOptions?)Deserializes a YAML payload from text.
Deserialize<T>(string, YamlTypeInfo<T>)Deserializes a payload using explicit type metadata.
Serialize(IBufferWriter<char>, object?, Type, YamlSerializerContext)Serializes a value to an IBufferWriter<T> destination using an explicit input type and generated metadata from a serializer context.
Serialize(IBufferWriter<char>, object?, Type, YamlSerializerOptions?)Serializes a value to an IBufferWriter<T> destination using an explicit input type.
Serialize(Stream, object?, YamlTypeInfo)Serializes a value to a stream using UTF-8 encoding and explicit type metadata.
Serialize(Stream, object?, Type, YamlSerializerContext)Serializes a value to a stream using UTF-8 encoding and generated metadata from a serializer context.
Serialize(Stream, object?, Type, YamlSerializerOptions?)Serializes a value to a stream using UTF-8 encoding and an explicit input type.
Serialize(TextWriter, object?, YamlTypeInfo)Serializes a value to a writer using explicit type metadata.
Serialize(TextWriter, object?, Type, YamlSerializerContext)Serializes a value to a writer using generated metadata from a serializer context.
Serialize(TextWriter, object?, Type, YamlSerializerOptions?)Serializes a value to a writer using an explicit input type.
Serialize(object?, YamlTypeInfo)Serializes a value using explicit type metadata.
Serialize(object?, Type, YamlSerializerContext)Serializes a value into YAML text using generated metadata from a serializer context.
Serialize(object?, Type, YamlSerializerOptions?)Serializes a value into YAML text using an explicit input type.
Serialize<T>(IBufferWriter<char>, T, YamlSerializerContext)Serializes a value to an IBufferWriter<T> destination using generated metadata from a serializer context.
Serialize<T>(IBufferWriter<char>, T, YamlSerializerOptions?)Serializes a value to an IBufferWriter<T> destination.
Serialize<T>(Stream, T, YamlSerializerContext)Serializes a value to a stream using UTF-8 encoding and generated metadata from a serializer context.
Serialize<T>(Stream, T, YamlSerializerOptions?)Serializes a value to a stream using UTF-8 encoding.
Serialize<T>(Stream, T, YamlTypeInfo<T>)Serializes a value to a stream using UTF-8 encoding and explicit type metadata.
Serialize<T>(TextWriter, T, YamlSerializerContext)Serializes a value to a writer using generated metadata from a serializer context.
Serialize<T>(TextWriter, T, YamlSerializerOptions?)Serializes a value to a writer.
Serialize<T>(TextWriter, T, YamlTypeInfo<T>)Serializes a value to a writer using explicit type metadata.
Serialize<T>(T, YamlSerializerContext)Serializes a value into YAML text using generated metadata from a serializer context.
Serialize<T>(T, YamlSerializerOptions?)Serializes a value into YAML text.
Serialize<T>(T, YamlTypeInfo<T>)Serializes a value using explicit type metadata.
TryDeserialize(Stream, Type, YamlSerializerContext, object?)Attempts to deserialize YAML from a stream using UTF-8 encoding and an explicit destination type using generated metadata from a serializer context.
TryDeserialize(Stream, Type, object?, YamlSerializerOptions?)Attempts to deserialize YAML from a stream using UTF-8 encoding and an explicit destination type.
TryDeserialize(TextReader, Type, YamlSerializerContext, object?)Attempts to deserialize YAML from a text reader using an explicit destination type and generated metadata from a serializer context.
TryDeserialize(TextReader, Type, object?, YamlSerializerOptions?)Attempts to deserialize YAML from a text reader using an explicit destination type.
TryDeserialize(string, Type, YamlSerializerContext, object?)Attempts to deserialize a YAML payload into an explicit destination type using generated metadata from a serializer context.
TryDeserialize(string, Type, object?, YamlSerializerOptions?)Attempts to deserialize a YAML payload into an explicit destination type.
TryDeserialize<T>(Stream, YamlSerializerContext, T?)Attempts to deserialize YAML from a stream using UTF-8 encoding and generated metadata from a serializer context.
TryDeserialize<T>(Stream, T?, YamlSerializerOptions?)Attempts to deserialize YAML from a stream using UTF-8 encoding.
TryDeserialize<T>(TextReader, YamlSerializerContext, T?)Attempts to deserialize YAML from a text reader using generated metadata from a serializer context.
TryDeserialize<T>(TextReader, T?, YamlSerializerOptions?)Attempts to deserialize YAML from a text reader.
TryDeserialize<T>(string, YamlSerializerContext, T?)Attempts to deserialize a YAML payload from text using generated metadata from a serializer context.
TryDeserialize<T>(string, T?, YamlSerializerOptions?)Attempts to deserialize a YAML payload from text.

Deserialize overloads

Deserialize(Stream, YamlTypeInfo)

YamlSerializer.cs

Deserializes a payload from a stream using UTF-8 encoding and explicit type metadata.

public static object? Deserialize(Stream utf8Stream, YamlTypeInfo typeInfo)
Parameters
utf8Stream Stream
The source stream.
typeInfo YamlTypeInfo
The metadata used for deserialization.
Returns

object? The deserialized value.

Exceptions
ArgumentNullException
utf8Stream or typeInfo is null.

Deserialize(Stream, Type, YamlSerializerContext)

YamlSerializer.cs

Deserializes YAML from a stream using UTF-8 encoding and generated metadata from a serializer context.

public static object? Deserialize(Stream utf8Stream, Type returnType, YamlSerializerContext context)
Parameters
utf8Stream Stream
The source stream.
returnType Type
The destination CLR type.
context YamlSerializerContext
The source-generated serializer context.
Returns

object? The deserialized value.

Exceptions
ArgumentNullException
utf8Stream, returnType, or context is null.
InvalidOperationException
No generated metadata is available for returnType in context.

Deserialize(Stream, Type, YamlSerializerOptions?)

YamlSerializer.cs

Deserializes YAML from a stream using UTF-8 encoding.

public static object? Deserialize(Stream utf8Stream, Type returnType, YamlSerializerOptions? options = null)
Parameters
utf8Stream Stream
The source stream.
returnType Type
The destination CLR type.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

object? The deserialized value.

Exceptions
ArgumentNullException
utf8Stream or returnType is null.

Deserialize(TextReader, YamlTypeInfo)

YamlSerializer.cs

Deserializes a payload from a text reader using explicit type metadata.

public static object? Deserialize(TextReader reader, YamlTypeInfo typeInfo)
Parameters
reader TextReader
The source reader.
typeInfo YamlTypeInfo
The metadata used for deserialization.
Returns

object? The deserialized value.

Exceptions
ArgumentNullException
reader or typeInfo is null.

Deserialize(TextReader, Type, YamlSerializerContext)

YamlSerializer.cs

Deserializes YAML from a text reader using an explicit destination type and generated metadata from a serializer context.

public static object? Deserialize(TextReader reader, Type returnType, YamlSerializerContext context)
Parameters
reader TextReader
The source reader.
returnType Type
The destination CLR type.
context YamlSerializerContext
The source-generated serializer context.
Returns

object? The deserialized value.

Exceptions
ArgumentNullException
reader, returnType, or context is null.
InvalidOperationException
No generated metadata is available for returnType in context.

Deserialize(TextReader, Type, YamlSerializerOptions?)

YamlSerializer.cs

Deserializes YAML from a text reader using an explicit destination type.

public static object? Deserialize(TextReader reader, Type returnType, YamlSerializerOptions? options = null)
Parameters
reader TextReader
The source reader.
returnType Type
The destination CLR type.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

object? The deserialized value.

Exceptions
ArgumentNullException
reader or returnType is null.

Deserialize(string, YamlTypeInfo)

YamlSerializer.cs

Deserializes a payload using explicit type metadata.

public static object? Deserialize(string yaml, YamlTypeInfo typeInfo)
Parameters
yaml string
The YAML payload.
typeInfo YamlTypeInfo
The metadata used for deserialization.
Returns

object? The deserialized value.

Exceptions
ArgumentNullException
yaml or typeInfo is null.

Deserialize(string, Type, YamlSerializerContext)

YamlSerializer.cs

Deserializes a YAML payload into an explicit destination type using generated metadata from a serializer context.

public static object? Deserialize(string yaml, Type returnType, YamlSerializerContext context)
Parameters
yaml string
The YAML payload.
returnType Type
The destination CLR type.
context YamlSerializerContext
The source-generated serializer context.
Returns

object? The deserialized value.

Exceptions
ArgumentNullException
yaml, returnType, or context is null.
InvalidOperationException
No generated metadata is available for returnType in context.

Deserialize(string, Type, YamlSerializerOptions?)

YamlSerializer.cs

Deserializes a YAML payload into an explicit destination type.

public static object? Deserialize(string yaml, Type returnType, YamlSerializerOptions? options = null)
Parameters
yaml string
The YAML payload.
returnType Type
The destination CLR type.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

object? The deserialized value.

Exceptions
ArgumentNullException
yaml or returnType is null.
InvalidOperationException
Reflection is disabled and no metadata is available from YamlSerializerOptions.TypeInfoResolver.

Deserialize<T>(Stream, YamlSerializerContext)

YamlSerializer.cs

Deserializes YAML from a stream using UTF-8 encoding and generated metadata from a serializer context.

public static T? Deserialize<T>(Stream utf8Stream, YamlSerializerContext context)
Type parameters
T
The destination CLR type.
Parameters
utf8Stream Stream
The source stream.
context YamlSerializerContext
The source-generated serializer context.
Returns

T? The deserialized value.

Exceptions
ArgumentNullException
utf8Stream or context is null.
InvalidOperationException
No generated metadata is available for T in context.

Deserialize<T>(Stream, YamlSerializerOptions?)

YamlSerializer.cs

Deserializes YAML from a stream using UTF-8 encoding.

public static T? Deserialize<T>(Stream utf8Stream, YamlSerializerOptions? options = null)
Type parameters
T
The destination CLR type.
Parameters
utf8Stream Stream
The source stream.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

T? The deserialized value.

Exceptions
ArgumentNullException
utf8Stream is null.

Deserialize<T>(Stream, YamlTypeInfo<T>)

YamlSerializer.cs

Deserializes a payload from a stream using UTF-8 encoding and explicit type metadata.

public static T? Deserialize<T>(Stream utf8Stream, YamlTypeInfo<T> typeInfo)
Type parameters
T
The represented CLR type.
Parameters
utf8Stream Stream
The source stream.
typeInfo YamlTypeInfo<T>
The metadata used for deserialization.
Returns

T? The deserialized value.

Exceptions
ArgumentNullException
utf8Stream or typeInfo is null.

Deserialize<T>(TextReader, YamlSerializerContext)

YamlSerializer.cs

Deserializes YAML from a text reader using generated metadata from a serializer context.

public static T? Deserialize<T>(TextReader reader, YamlSerializerContext context)
Type parameters
T
The destination CLR type.
Parameters
reader TextReader
The source reader.
context YamlSerializerContext
The source-generated serializer context.
Returns

T? The deserialized value.

Exceptions
ArgumentNullException
reader or context is null.
InvalidOperationException
No generated metadata is available for T in context.

Deserialize<T>(TextReader, YamlSerializerOptions?)

YamlSerializer.cs

Deserializes YAML from a text reader.

public static T? Deserialize<T>(TextReader reader, YamlSerializerOptions? options = null)
Type parameters
T
The destination CLR type.
Parameters
reader TextReader
The source reader.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

T? The deserialized value.

Exceptions
ArgumentNullException
reader is null.

Deserialize<T>(TextReader, YamlTypeInfo<T>)

YamlSerializer.cs

Deserializes a payload from a text reader using explicit type metadata.

public static T? Deserialize<T>(TextReader reader, YamlTypeInfo<T> typeInfo)
Type parameters
T
The represented CLR type.
Parameters
reader TextReader
The source reader.
typeInfo YamlTypeInfo<T>
The metadata used for deserialization.
Returns

T? The deserialized value.

Exceptions
ArgumentNullException
reader or typeInfo is null.

Deserialize<T>(string, YamlSerializerContext)

YamlSerializer.cs

Deserializes a YAML payload from text using generated metadata from a serializer context.

public static T? Deserialize<T>(string yaml, YamlSerializerContext context)
Type parameters
T
The destination CLR type.
Parameters
yaml string
The YAML payload.
context YamlSerializerContext
The source-generated serializer context.
Returns

T? The deserialized value.

Exceptions
ArgumentNullException
yaml or context is null.
InvalidOperationException
No generated metadata is available for T in context.

Deserialize<T>(string, YamlSerializerOptions?)

YamlSerializer.cs

Deserializes a YAML payload from text.

public static T? Deserialize<T>(string yaml, YamlSerializerOptions? options = null)
Type parameters
T
The destination CLR type.
Parameters
yaml string
The YAML payload.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

T? The deserialized value.

Exceptions
ArgumentNullException
yaml is null.

Deserialize<T>(string, YamlTypeInfo<T>)

YamlSerializer.cs

Deserializes a payload using explicit type metadata.

public static T? Deserialize<T>(string yaml, YamlTypeInfo<T> typeInfo)
Type parameters
T
The represented CLR type.
Parameters
yaml string
The YAML payload.
typeInfo YamlTypeInfo<T>
The metadata used for deserialization.
Returns

T? The deserialized value.

Exceptions
ArgumentNullException
yaml or typeInfo is null.

Serialize overloads

Serialize(IBufferWriter<char>, object?, Type, YamlSerializerContext)

YamlSerializer.cs

Serializes a value to an IBufferWriter<T> destination using an explicit input type and generated metadata from a serializer context.

public static void Serialize(IBufferWriter<char> destination, object? value, Type inputType, YamlSerializerContext context)
Parameters
destination IBufferWriter<char>
The destination buffer writer.
value object?
The value to serialize.
inputType Type
The declared input type.
context YamlSerializerContext
The source-generated serializer context.
Exceptions
ArgumentNullException
destination, inputType, or context is null.

Serialize(IBufferWriter<char>, object?, Type, YamlSerializerOptions?)

YamlSerializer.cs

Serializes a value to an IBufferWriter<T> destination using an explicit input type.

public static void Serialize(IBufferWriter<char> destination, object? value, Type inputType, YamlSerializerOptions? options = null)
Parameters
destination IBufferWriter<char>
The destination buffer writer.
value object?
The value to serialize.
inputType Type
The declared input type.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Exceptions
ArgumentNullException
destination or inputType is null.

Serialize(Stream, object?, YamlTypeInfo)

YamlSerializer.cs

Serializes a value to a stream using UTF-8 encoding and explicit type metadata.

public static void Serialize(Stream utf8Stream, object? value, YamlTypeInfo typeInfo)
Parameters
utf8Stream Stream
The destination stream.
value object?
The value to serialize.
typeInfo YamlTypeInfo
The metadata used for serialization.
Exceptions
ArgumentNullException
utf8Stream or typeInfo is null.

Serialize(Stream, object?, Type, YamlSerializerContext)

YamlSerializer.cs

Serializes a value to a stream using UTF-8 encoding and generated metadata from a serializer context.

public static void Serialize(Stream utf8Stream, object? value, Type inputType, YamlSerializerContext context)
Parameters
utf8Stream Stream
The destination stream.
value object?
The value to serialize.
inputType Type
The declared input type.
context YamlSerializerContext
The source-generated serializer context.
Exceptions
ArgumentNullException
utf8Stream, inputType, or context is null.
InvalidOperationException
No generated metadata is available for inputType in context.

Serialize(Stream, object?, Type, YamlSerializerOptions?)

YamlSerializer.cs

Serializes a value to a stream using UTF-8 encoding and an explicit input type.

public static void Serialize(Stream utf8Stream, object? value, Type inputType, YamlSerializerOptions? options = null)
Parameters
utf8Stream Stream
The destination stream.
value object?
The value to serialize.
inputType Type
The declared input type.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Exceptions
ArgumentNullException
utf8Stream or inputType is null.

Serialize(TextWriter, object?, YamlTypeInfo)

YamlSerializer.cs

Serializes a value to a writer using explicit type metadata.

public static void Serialize(TextWriter writer, object? value, YamlTypeInfo typeInfo)
Parameters
writer TextWriter
The destination writer.
value object?
The value to serialize.
typeInfo YamlTypeInfo
The metadata used for serialization.
Exceptions
ArgumentNullException
writer or typeInfo is null.

Serialize(TextWriter, object?, Type, YamlSerializerContext)

YamlSerializer.cs

Serializes a value to a writer using generated metadata from a serializer context.

public static void Serialize(TextWriter writer, object? value, Type inputType, YamlSerializerContext context)
Parameters
writer TextWriter
The destination writer.
value object?
The value to serialize.
inputType Type
The declared input type.
context YamlSerializerContext
The source-generated serializer context.
Exceptions
ArgumentNullException
writer, inputType, or context is null.
InvalidOperationException
No generated metadata is available for inputType in context.

Serialize(TextWriter, object?, Type, YamlSerializerOptions?)

YamlSerializer.cs

Serializes a value to a writer using an explicit input type.

public static void Serialize(TextWriter writer, object? value, Type inputType, YamlSerializerOptions? options = null)
Parameters
writer TextWriter
The destination writer.
value object?
The value to serialize.
inputType Type
The declared input type.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Exceptions
ArgumentNullException
writer or inputType is null.

Serialize(object?, YamlTypeInfo)

YamlSerializer.cs

Serializes a value using explicit type metadata.

public static string Serialize(object? value, YamlTypeInfo typeInfo)
Parameters
value object?
The value to serialize.
typeInfo YamlTypeInfo
The metadata used for serialization.
Returns

string A YAML payload.

Exceptions
ArgumentNullException
typeInfo is null.

Serialize(object?, Type, YamlSerializerContext)

YamlSerializer.cs

Serializes a value into YAML text using generated metadata from a serializer context.

public static string Serialize(object? value, Type inputType, YamlSerializerContext context)
Parameters
value object?
The value to serialize.
inputType Type
The declared input type.
context YamlSerializerContext
The source-generated serializer context.
Returns

string A YAML payload.

Exceptions
ArgumentNullException
inputType or context is null.
InvalidOperationException
No generated metadata is available for inputType in context.

Serialize(object?, Type, YamlSerializerOptions?)

YamlSerializer.cs

Serializes a value into YAML text using an explicit input type.

public static string Serialize(object? value, Type inputType, YamlSerializerOptions? options = null)
Parameters
value object?
The value to serialize.
inputType Type
The declared input type.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

string A YAML payload.

Exceptions
ArgumentNullException
inputType is null.
InvalidOperationException
Reflection is disabled and no metadata is available from YamlSerializerOptions.TypeInfoResolver.

Serialize<T>(IBufferWriter<char>, T, YamlSerializerContext)

YamlSerializer.cs

Serializes a value to an IBufferWriter<T> destination using generated metadata from a serializer context.

public static void Serialize<T>(IBufferWriter<char> destination, T value, YamlSerializerContext context)
Type parameters
T
The CLR type to serialize.
Parameters
destination IBufferWriter<char>
The destination buffer writer.
value T
The value to serialize.
context YamlSerializerContext
The source-generated serializer context.
Exceptions
ArgumentNullException
destination or context is null.

Serialize<T>(IBufferWriter<char>, T, YamlSerializerOptions?)

YamlSerializer.cs

Serializes a value to an IBufferWriter<T> destination.

public static void Serialize<T>(IBufferWriter<char> destination, T value, YamlSerializerOptions? options = null)
Type parameters
T
The CLR type to serialize.
Parameters
destination IBufferWriter<char>
The destination buffer writer.
value T
The value to serialize.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Exceptions
ArgumentNullException
destination is null.

Serialize<T>(Stream, T, YamlSerializerContext)

YamlSerializer.cs

Serializes a value to a stream using UTF-8 encoding and generated metadata from a serializer context.

public static void Serialize<T>(Stream utf8Stream, T value, YamlSerializerContext context)
Type parameters
T
The CLR type to serialize.
Parameters
utf8Stream Stream
The destination stream.
value T
The value to serialize.
context YamlSerializerContext
The source-generated serializer context.
Exceptions
ArgumentNullException
utf8Stream or context is null.
InvalidOperationException
No generated metadata is available for T in context.

Serialize<T>(Stream, T, YamlSerializerOptions?)

YamlSerializer.cs

Serializes a value to a stream using UTF-8 encoding.

public static void Serialize<T>(Stream utf8Stream, T value, YamlSerializerOptions? options = null)
Type parameters
T
The CLR type to serialize.
Parameters
utf8Stream Stream
The destination stream.
value T
The value to serialize.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Exceptions
ArgumentNullException
utf8Stream is null.

Serialize<T>(Stream, T, YamlTypeInfo<T>)

YamlSerializer.cs

Serializes a value to a stream using UTF-8 encoding and explicit type metadata.

public static void Serialize<T>(Stream utf8Stream, T value, YamlTypeInfo<T> typeInfo)
Type parameters
T
The represented CLR type.
Parameters
utf8Stream Stream
The destination stream.
value T
The value to serialize.
typeInfo YamlTypeInfo<T>
The metadata used for serialization.
Exceptions
ArgumentNullException
utf8Stream or typeInfo is null.

Serialize<T>(TextWriter, T, YamlSerializerContext)

YamlSerializer.cs

Serializes a value to a writer using generated metadata from a serializer context.

public static void Serialize<T>(TextWriter writer, T value, YamlSerializerContext context)
Type parameters
T
The CLR type to serialize.
Parameters
writer TextWriter
The destination writer.
value T
The value to serialize.
context YamlSerializerContext
The source-generated serializer context.
Exceptions
ArgumentNullException
writer or context is null.
InvalidOperationException
No generated metadata is available for T in context.

Serialize<T>(TextWriter, T, YamlSerializerOptions?)

YamlSerializer.cs

Serializes a value to a writer.

public static void Serialize<T>(TextWriter writer, T value, YamlSerializerOptions? options = null)
Type parameters
T
The CLR type to serialize.
Parameters
writer TextWriter
The destination writer.
value T
The value to serialize.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Exceptions
ArgumentNullException
writer is null.

Serialize<T>(TextWriter, T, YamlTypeInfo<T>)

YamlSerializer.cs

Serializes a value to a writer using explicit type metadata.

public static void Serialize<T>(TextWriter writer, T value, YamlTypeInfo<T> typeInfo)
Type parameters
T
The represented CLR type.
Parameters
writer TextWriter
The destination writer.
value T
The value to serialize.
typeInfo YamlTypeInfo<T>
The metadata used for serialization.
Exceptions
ArgumentNullException
writer or typeInfo is null.

Serialize<T>(T, YamlSerializerContext)

YamlSerializer.cs

Serializes a value into YAML text using generated metadata from a serializer context.

public static string Serialize<T>(T value, YamlSerializerContext context)
Type parameters
T
The CLR type to serialize.
Parameters
value T
The value to serialize.
context YamlSerializerContext
The source-generated serializer context.
Returns

string A YAML payload.

Exceptions
ArgumentNullException
context is null.
InvalidOperationException
No generated metadata is available for T in context.

Serialize<T>(T, YamlSerializerOptions?)

YamlSerializer.cs

Serializes a value into YAML text.

public static string Serialize<T>(T value, YamlSerializerOptions? options = null)
Type parameters
T
The CLR type to serialize.
Parameters
value T
The value to serialize.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

string A YAML payload.

Serialize<T>(T, YamlTypeInfo<T>)

YamlSerializer.cs

Serializes a value using explicit type metadata.

public static string Serialize<T>(T value, YamlTypeInfo<T> typeInfo)
Type parameters
T
The represented CLR type.
Parameters
value T
The value to serialize.
typeInfo YamlTypeInfo<T>
The metadata used for serialization.
Returns

string A YAML payload.

Exceptions
ArgumentNullException
typeInfo is null.

TryDeserialize overloads

TryDeserialize(Stream, Type, YamlSerializerContext, object?)

YamlSerializer.cs

Attempts to deserialize YAML from a stream using UTF-8 encoding and an explicit destination type using generated metadata from a serializer context.

public static bool TryDeserialize(Stream utf8Stream, Type returnType, YamlSerializerContext context, out object? value)
Parameters
utf8Stream Stream
The source stream.
returnType Type
The destination CLR type.
context YamlSerializerContext
The source-generated serializer context.
value object?
The deserialized value when successful; otherwise null.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
utf8Stream, returnType, or context is null.

TryDeserialize(Stream, Type, object?, YamlSerializerOptions?)

YamlSerializer.cs

Attempts to deserialize YAML from a stream using UTF-8 encoding and an explicit destination type.

public static bool TryDeserialize(Stream utf8Stream, Type returnType, out object? value, YamlSerializerOptions? options = null)
Parameters
utf8Stream Stream
The source stream.
returnType Type
The destination CLR type.
value object?
The deserialized value when successful; otherwise null.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
utf8Stream or returnType is null.

TryDeserialize(TextReader, Type, YamlSerializerContext, object?)

YamlSerializer.cs

Attempts to deserialize YAML from a text reader using an explicit destination type and generated metadata from a serializer context.

public static bool TryDeserialize(TextReader reader, Type returnType, YamlSerializerContext context, out object? value)
Parameters
reader TextReader
The source reader.
returnType Type
The destination CLR type.
context YamlSerializerContext
The source-generated serializer context.
value object?
The deserialized value when successful; otherwise null.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
reader, returnType, or context is null.

TryDeserialize(TextReader, Type, object?, YamlSerializerOptions?)

YamlSerializer.cs

Attempts to deserialize YAML from a text reader using an explicit destination type.

public static bool TryDeserialize(TextReader reader, Type returnType, out object? value, YamlSerializerOptions? options = null)
Parameters
reader TextReader
The source reader.
returnType Type
The destination CLR type.
value object?
The deserialized value when successful; otherwise null.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
reader or returnType is null.

TryDeserialize(string, Type, YamlSerializerContext, object?)

YamlSerializer.cs

Attempts to deserialize a YAML payload into an explicit destination type using generated metadata from a serializer context.

public static bool TryDeserialize(string yaml, Type returnType, YamlSerializerContext context, out object? value)
Parameters
yaml string
The YAML payload.
returnType Type
The destination CLR type.
context YamlSerializerContext
The source-generated serializer context.
value object?
The deserialized value when successful; otherwise null.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
yaml, returnType, or context is null.

TryDeserialize(string, Type, object?, YamlSerializerOptions?)

YamlSerializer.cs

Attempts to deserialize a YAML payload into an explicit destination type.

public static bool TryDeserialize(string yaml, Type returnType, out object? value, YamlSerializerOptions? options = null)
Parameters
yaml string
The YAML payload.
returnType Type
The destination CLR type.
value object?
The deserialized value when successful; otherwise null.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
yaml or returnType is null.

TryDeserialize<T>(Stream, YamlSerializerContext, T?)

YamlSerializer.cs

Attempts to deserialize YAML from a stream using UTF-8 encoding and generated metadata from a serializer context.

public static bool TryDeserialize<T>(Stream utf8Stream, YamlSerializerContext context, out T? value)
Type parameters
T
The destination CLR type.
Parameters
utf8Stream Stream
The source stream.
context YamlSerializerContext
The source-generated serializer context.
value T?
The deserialized value when successful; otherwise default.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
utf8Stream or context is null.

TryDeserialize<T>(Stream, T?, YamlSerializerOptions?)

YamlSerializer.cs

Attempts to deserialize YAML from a stream using UTF-8 encoding.

public static bool TryDeserialize<T>(Stream utf8Stream, out T? value, YamlSerializerOptions? options = null)
Type parameters
T
The destination CLR type.
Parameters
utf8Stream Stream
The source stream.
value T?
The deserialized value when successful; otherwise default.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
utf8Stream is null.

TryDeserialize<T>(TextReader, YamlSerializerContext, T?)

YamlSerializer.cs

Attempts to deserialize YAML from a text reader using generated metadata from a serializer context.

public static bool TryDeserialize<T>(TextReader reader, YamlSerializerContext context, out T? value)
Type parameters
T
The destination CLR type.
Parameters
reader TextReader
The source reader.
context YamlSerializerContext
The source-generated serializer context.
value T?
The deserialized value when successful; otherwise default.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
reader or context is null.

TryDeserialize<T>(TextReader, T?, YamlSerializerOptions?)

YamlSerializer.cs

Attempts to deserialize YAML from a text reader.

public static bool TryDeserialize<T>(TextReader reader, out T? value, YamlSerializerOptions? options = null)
Type parameters
T
The destination CLR type.
Parameters
reader TextReader
The source reader.
value T?
The deserialized value when successful; otherwise default.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
reader is null.

TryDeserialize<T>(string, YamlSerializerContext, T?)

YamlSerializer.cs

Attempts to deserialize a YAML payload from text using generated metadata from a serializer context.

public static bool TryDeserialize<T>(string yaml, YamlSerializerContext context, out T? value)
Type parameters
T
The destination CLR type.
Parameters
yaml string
The YAML payload.
context YamlSerializerContext
The source-generated serializer context.
value T?
The deserialized value when successful; otherwise default.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
yaml or context is null.

TryDeserialize<T>(string, T?, YamlSerializerOptions?)

YamlSerializer.cs

Attempts to deserialize a YAML payload from text.

public static bool TryDeserialize<T>(string yaml, out T? value, YamlSerializerOptions? options = null)
Type parameters
T
The destination CLR type.
Parameters
yaml string
The YAML payload.
value T?
The deserialized value when successful; otherwise default.
options YamlSerializerOptions?
The serializer options. If null, YamlSerializerOptions.Default is used.
Returns

bool true when deserialization succeeded; otherwise false.

Exceptions
ArgumentNullException
yaml is null.