YamlSerializer Class
Serializes and deserializes YAML payloads, following a System.Text.Json-style API shape.
public static class YamlSerializerProperties
| Name | Description |
|---|---|
| IsReflectionEnabledByDefault | Gets a value indicating whether reflection-based serialization is enabled by default. |
IsReflectionEnabledByDefault
YamlSerializer.csMethods
| Name | Description |
|---|---|
| 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.csDeserializes a payload from a stream using UTF-8 encoding and explicit type metadata.
public static object? Deserialize(Stream utf8Stream, YamlTypeInfo typeInfo)Parameters
utf8StreamStream- The source stream.
typeInfoYamlTypeInfo- The metadata used for deserialization.
Returns
object? The deserialized value.
Exceptions
ArgumentNullExceptionutf8StreamortypeInfoisnull.
Deserialize(Stream, Type, YamlSerializerContext)
YamlSerializer.csDeserializes 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
utf8StreamStream- The source stream.
returnTypeType- The destination CLR type.
contextYamlSerializerContext- The source-generated serializer context.
Returns
object? The deserialized value.
Exceptions
ArgumentNullExceptionutf8Stream,returnType, orcontextisnull.InvalidOperationException- No generated metadata is available for
returnTypeincontext.
Deserialize(Stream, Type, YamlSerializerOptions?)
YamlSerializer.csDeserializes YAML from a stream using UTF-8 encoding.
public static object? Deserialize(Stream utf8Stream, Type returnType, YamlSerializerOptions? options = null)Parameters
utf8StreamStream- The source stream.
returnTypeType- The destination CLR type.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
object? The deserialized value.
Exceptions
ArgumentNullExceptionutf8StreamorreturnTypeisnull.
Deserialize(TextReader, YamlTypeInfo)
YamlSerializer.csDeserializes a payload from a text reader using explicit type metadata.
public static object? Deserialize(TextReader reader, YamlTypeInfo typeInfo)Parameters
readerTextReader- The source reader.
typeInfoYamlTypeInfo- The metadata used for deserialization.
Returns
object? The deserialized value.
Exceptions
ArgumentNullExceptionreaderortypeInfoisnull.
Deserialize(TextReader, Type, YamlSerializerContext)
YamlSerializer.csDeserializes 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
readerTextReader- The source reader.
returnTypeType- The destination CLR type.
contextYamlSerializerContext- The source-generated serializer context.
Returns
object? The deserialized value.
Exceptions
ArgumentNullExceptionreader,returnType, orcontextisnull.InvalidOperationException- No generated metadata is available for
returnTypeincontext.
Deserialize(TextReader, Type, YamlSerializerOptions?)
YamlSerializer.csDeserializes YAML from a text reader using an explicit destination type.
public static object? Deserialize(TextReader reader, Type returnType, YamlSerializerOptions? options = null)Parameters
readerTextReader- The source reader.
returnTypeType- The destination CLR type.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
object? The deserialized value.
Exceptions
ArgumentNullExceptionreaderorreturnTypeisnull.
Deserialize(string, YamlTypeInfo)
YamlSerializer.csDeserializes a payload using explicit type metadata.
public static object? Deserialize(string yaml, YamlTypeInfo typeInfo)Parameters
yamlstring- The YAML payload.
typeInfoYamlTypeInfo- The metadata used for deserialization.
Returns
object? The deserialized value.
Exceptions
ArgumentNullExceptionyamlortypeInfoisnull.
Deserialize(string, Type, YamlSerializerContext)
YamlSerializer.csDeserializes 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
yamlstring- The YAML payload.
returnTypeType- The destination CLR type.
contextYamlSerializerContext- The source-generated serializer context.
Returns
object? The deserialized value.
Exceptions
ArgumentNullExceptionyaml,returnType, orcontextisnull.InvalidOperationException- No generated metadata is available for
returnTypeincontext.
Deserialize(string, Type, YamlSerializerOptions?)
YamlSerializer.csDeserializes a YAML payload into an explicit destination type.
public static object? Deserialize(string yaml, Type returnType, YamlSerializerOptions? options = null)Parameters
yamlstring- The YAML payload.
returnTypeType- The destination CLR type.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
object? The deserialized value.
Exceptions
ArgumentNullExceptionyamlorreturnTypeisnull.InvalidOperationException- Reflection is disabled and no metadata is available from
YamlSerializerOptions.TypeInfoResolver.
Deserialize<T>(Stream, YamlSerializerContext)
YamlSerializer.csDeserializes 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
utf8StreamStream- The source stream.
contextYamlSerializerContext- The source-generated serializer context.
Returns
T? The deserialized value.
Exceptions
ArgumentNullExceptionutf8Streamorcontextisnull.InvalidOperationException- No generated metadata is available for
Tincontext.
Deserialize<T>(Stream, YamlSerializerOptions?)
YamlSerializer.csDeserializes 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
utf8StreamStream- The source stream.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
T? The deserialized value.
Exceptions
ArgumentNullExceptionutf8Streamisnull.
Deserialize<T>(Stream, YamlTypeInfo<T>)
YamlSerializer.csDeserializes 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
utf8StreamStream- The source stream.
typeInfoYamlTypeInfo<T>- The metadata used for deserialization.
Returns
T? The deserialized value.
Exceptions
ArgumentNullExceptionutf8StreamortypeInfoisnull.
Deserialize<T>(TextReader, YamlSerializerContext)
YamlSerializer.csDeserializes 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
readerTextReader- The source reader.
contextYamlSerializerContext- The source-generated serializer context.
Returns
T? The deserialized value.
Exceptions
ArgumentNullExceptionreaderorcontextisnull.InvalidOperationException- No generated metadata is available for
Tincontext.
Deserialize<T>(TextReader, YamlSerializerOptions?)
YamlSerializer.csDeserializes YAML from a text reader.
public static T? Deserialize<T>(TextReader reader, YamlSerializerOptions? options = null)Type parameters
T- The destination CLR type.
Parameters
readerTextReader- The source reader.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
T? The deserialized value.
Exceptions
ArgumentNullExceptionreaderisnull.
Deserialize<T>(TextReader, YamlTypeInfo<T>)
YamlSerializer.csDeserializes 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
readerTextReader- The source reader.
typeInfoYamlTypeInfo<T>- The metadata used for deserialization.
Returns
T? The deserialized value.
Exceptions
ArgumentNullExceptionreaderortypeInfoisnull.
Deserialize<T>(string, YamlSerializerContext)
YamlSerializer.csDeserializes 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
yamlstring- The YAML payload.
contextYamlSerializerContext- The source-generated serializer context.
Returns
T? The deserialized value.
Exceptions
ArgumentNullExceptionyamlorcontextisnull.InvalidOperationException- No generated metadata is available for
Tincontext.
Deserialize<T>(string, YamlSerializerOptions?)
YamlSerializer.csDeserializes a YAML payload from text.
public static T? Deserialize<T>(string yaml, YamlSerializerOptions? options = null)Type parameters
T- The destination CLR type.
Parameters
yamlstring- The YAML payload.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
T? The deserialized value.
Exceptions
ArgumentNullExceptionyamlisnull.
Deserialize<T>(string, YamlTypeInfo<T>)
YamlSerializer.csDeserializes a payload using explicit type metadata.
public static T? Deserialize<T>(string yaml, YamlTypeInfo<T> typeInfo)Type parameters
T- The represented CLR type.
Parameters
yamlstring- The YAML payload.
typeInfoYamlTypeInfo<T>- The metadata used for deserialization.
Returns
T? The deserialized value.
Exceptions
ArgumentNullExceptionyamlortypeInfoisnull.
Serialize overloads
Serialize(IBufferWriter<char>, object?, Type, YamlSerializerContext)
YamlSerializer.csSerializes 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
destinationIBufferWriter<char>- The destination buffer writer.
valueobject?- The value to serialize.
inputTypeType- The declared input type.
contextYamlSerializerContext- The source-generated serializer context.
Exceptions
ArgumentNullExceptiondestination,inputType, orcontextisnull.
Serialize(IBufferWriter<char>, object?, Type, YamlSerializerOptions?)
YamlSerializer.csSerializes 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
destinationIBufferWriter<char>- The destination buffer writer.
valueobject?- The value to serialize.
inputTypeType- The declared input type.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Exceptions
ArgumentNullExceptiondestinationorinputTypeisnull.
Serialize(Stream, object?, YamlTypeInfo)
YamlSerializer.csSerializes a value to a stream using UTF-8 encoding and explicit type metadata.
public static void Serialize(Stream utf8Stream, object? value, YamlTypeInfo typeInfo)Parameters
utf8StreamStream- The destination stream.
valueobject?- The value to serialize.
typeInfoYamlTypeInfo- The metadata used for serialization.
Exceptions
ArgumentNullExceptionutf8StreamortypeInfoisnull.
Serialize(Stream, object?, Type, YamlSerializerContext)
YamlSerializer.csSerializes 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
utf8StreamStream- The destination stream.
valueobject?- The value to serialize.
inputTypeType- The declared input type.
contextYamlSerializerContext- The source-generated serializer context.
Exceptions
ArgumentNullExceptionutf8Stream,inputType, orcontextisnull.InvalidOperationException- No generated metadata is available for
inputTypeincontext.
Serialize(Stream, object?, Type, YamlSerializerOptions?)
YamlSerializer.csSerializes 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
utf8StreamStream- The destination stream.
valueobject?- The value to serialize.
inputTypeType- The declared input type.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Exceptions
ArgumentNullExceptionutf8StreamorinputTypeisnull.
Serialize(TextWriter, object?, YamlTypeInfo)
YamlSerializer.csSerializes a value to a writer using explicit type metadata.
public static void Serialize(TextWriter writer, object? value, YamlTypeInfo typeInfo)Parameters
writerTextWriter- The destination writer.
valueobject?- The value to serialize.
typeInfoYamlTypeInfo- The metadata used for serialization.
Exceptions
ArgumentNullExceptionwriterortypeInfoisnull.
Serialize(TextWriter, object?, Type, YamlSerializerContext)
YamlSerializer.csSerializes 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
writerTextWriter- The destination writer.
valueobject?- The value to serialize.
inputTypeType- The declared input type.
contextYamlSerializerContext- The source-generated serializer context.
Exceptions
ArgumentNullExceptionwriter,inputType, orcontextisnull.InvalidOperationException- No generated metadata is available for
inputTypeincontext.
Serialize(TextWriter, object?, Type, YamlSerializerOptions?)
YamlSerializer.csSerializes a value to a writer using an explicit input type.
public static void Serialize(TextWriter writer, object? value, Type inputType, YamlSerializerOptions? options = null)Parameters
writerTextWriter- The destination writer.
valueobject?- The value to serialize.
inputTypeType- The declared input type.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Exceptions
ArgumentNullExceptionwriterorinputTypeisnull.
Serialize(object?, YamlTypeInfo)
YamlSerializer.csSerializes a value using explicit type metadata.
public static string Serialize(object? value, YamlTypeInfo typeInfo)Parameters
valueobject?- The value to serialize.
typeInfoYamlTypeInfo- The metadata used for serialization.
Returns
string A YAML payload.
Exceptions
ArgumentNullExceptiontypeInfoisnull.
Serialize(object?, Type, YamlSerializerContext)
YamlSerializer.csSerializes a value into YAML text using generated metadata from a serializer context.
public static string Serialize(object? value, Type inputType, YamlSerializerContext context)Parameters
valueobject?- The value to serialize.
inputTypeType- The declared input type.
contextYamlSerializerContext- The source-generated serializer context.
Returns
string A YAML payload.
Exceptions
ArgumentNullExceptioninputTypeorcontextisnull.InvalidOperationException- No generated metadata is available for
inputTypeincontext.
Serialize(object?, Type, YamlSerializerOptions?)
YamlSerializer.csSerializes a value into YAML text using an explicit input type.
public static string Serialize(object? value, Type inputType, YamlSerializerOptions? options = null)Parameters
valueobject?- The value to serialize.
inputTypeType- The declared input type.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
string A YAML payload.
Exceptions
ArgumentNullExceptioninputTypeisnull.InvalidOperationException- Reflection is disabled and no metadata is available from
YamlSerializerOptions.TypeInfoResolver.
Serialize<T>(IBufferWriter<char>, T, YamlSerializerContext)
YamlSerializer.csSerializes 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
destinationIBufferWriter<char>- The destination buffer writer.
valueT- The value to serialize.
contextYamlSerializerContext- The source-generated serializer context.
Exceptions
ArgumentNullExceptiondestinationorcontextisnull.
Serialize<T>(IBufferWriter<char>, T, YamlSerializerOptions?)
YamlSerializer.csSerializes 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
destinationIBufferWriter<char>- The destination buffer writer.
valueT- The value to serialize.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Exceptions
ArgumentNullExceptiondestinationisnull.
Serialize<T>(Stream, T, YamlSerializerContext)
YamlSerializer.csSerializes 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
utf8StreamStream- The destination stream.
valueT- The value to serialize.
contextYamlSerializerContext- The source-generated serializer context.
Exceptions
ArgumentNullExceptionutf8Streamorcontextisnull.InvalidOperationException- No generated metadata is available for
Tincontext.
Serialize<T>(Stream, T, YamlSerializerOptions?)
YamlSerializer.csSerializes 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
utf8StreamStream- The destination stream.
valueT- The value to serialize.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Exceptions
ArgumentNullExceptionutf8Streamisnull.
Serialize<T>(Stream, T, YamlTypeInfo<T>)
YamlSerializer.csSerializes 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
utf8StreamStream- The destination stream.
valueT- The value to serialize.
typeInfoYamlTypeInfo<T>- The metadata used for serialization.
Exceptions
ArgumentNullExceptionutf8StreamortypeInfoisnull.
Serialize<T>(TextWriter, T, YamlSerializerContext)
YamlSerializer.csSerializes 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
writerTextWriter- The destination writer.
valueT- The value to serialize.
contextYamlSerializerContext- The source-generated serializer context.
Exceptions
ArgumentNullExceptionwriterorcontextisnull.InvalidOperationException- No generated metadata is available for
Tincontext.
Serialize<T>(TextWriter, T, YamlSerializerOptions?)
YamlSerializer.csSerializes 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
writerTextWriter- The destination writer.
valueT- The value to serialize.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Exceptions
ArgumentNullExceptionwriterisnull.
Serialize<T>(TextWriter, T, YamlTypeInfo<T>)
YamlSerializer.csSerializes 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
writerTextWriter- The destination writer.
valueT- The value to serialize.
typeInfoYamlTypeInfo<T>- The metadata used for serialization.
Exceptions
ArgumentNullExceptionwriterortypeInfoisnull.
Serialize<T>(T, YamlSerializerContext)
YamlSerializer.csSerializes 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
valueT- The value to serialize.
contextYamlSerializerContext- The source-generated serializer context.
Returns
string A YAML payload.
Exceptions
ArgumentNullExceptioncontextisnull.InvalidOperationException- No generated metadata is available for
Tincontext.
Serialize<T>(T, YamlSerializerOptions?)
YamlSerializer.csSerializes a value into YAML text.
public static string Serialize<T>(T value, YamlSerializerOptions? options = null)Type parameters
T- The CLR type to serialize.
Parameters
valueT- The value to serialize.
optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
string A YAML payload.
Serialize<T>(T, YamlTypeInfo<T>)
YamlSerializer.csSerializes a value using explicit type metadata.
public static string Serialize<T>(T value, YamlTypeInfo<T> typeInfo)Type parameters
T- The represented CLR type.
Parameters
valueT- The value to serialize.
typeInfoYamlTypeInfo<T>- The metadata used for serialization.
Returns
string A YAML payload.
Exceptions
ArgumentNullExceptiontypeInfoisnull.
TryDeserialize overloads
TryDeserialize(Stream, Type, YamlSerializerContext, object?)
YamlSerializer.csAttempts 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
utf8StreamStream- The source stream.
returnTypeType- The destination CLR type.
contextYamlSerializerContext- The source-generated serializer context.
valueobject?- The deserialized value when successful; otherwise
null.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionutf8Stream,returnType, orcontextisnull.
TryDeserialize(Stream, Type, object?, YamlSerializerOptions?)
YamlSerializer.csAttempts 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
utf8StreamStream- The source stream.
returnTypeType- The destination CLR type.
valueobject?- The deserialized value when successful; otherwise
null. optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionutf8StreamorreturnTypeisnull.
TryDeserialize(TextReader, Type, YamlSerializerContext, object?)
YamlSerializer.csAttempts 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
readerTextReader- The source reader.
returnTypeType- The destination CLR type.
contextYamlSerializerContext- The source-generated serializer context.
valueobject?- The deserialized value when successful; otherwise
null.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionreader,returnType, orcontextisnull.
TryDeserialize(TextReader, Type, object?, YamlSerializerOptions?)
YamlSerializer.csAttempts 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
readerTextReader- The source reader.
returnTypeType- The destination CLR type.
valueobject?- The deserialized value when successful; otherwise
null. optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionreaderorreturnTypeisnull.
TryDeserialize(string, Type, YamlSerializerContext, object?)
YamlSerializer.csAttempts 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
yamlstring- The YAML payload.
returnTypeType- The destination CLR type.
contextYamlSerializerContext- The source-generated serializer context.
valueobject?- The deserialized value when successful; otherwise
null.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionyaml,returnType, orcontextisnull.
TryDeserialize(string, Type, object?, YamlSerializerOptions?)
YamlSerializer.csAttempts 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
yamlstring- The YAML payload.
returnTypeType- The destination CLR type.
valueobject?- The deserialized value when successful; otherwise
null. optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionyamlorreturnTypeisnull.
TryDeserialize<T>(Stream, YamlSerializerContext, T?)
YamlSerializer.csAttempts 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
utf8StreamStream- The source stream.
contextYamlSerializerContext- The source-generated serializer context.
valueT?- The deserialized value when successful; otherwise
default.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionutf8Streamorcontextisnull.
TryDeserialize<T>(Stream, T?, YamlSerializerOptions?)
YamlSerializer.csAttempts 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
utf8StreamStream- The source stream.
valueT?- The deserialized value when successful; otherwise
default. optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionutf8Streamisnull.
TryDeserialize<T>(TextReader, YamlSerializerContext, T?)
YamlSerializer.csAttempts 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
readerTextReader- The source reader.
contextYamlSerializerContext- The source-generated serializer context.
valueT?- The deserialized value when successful; otherwise
default.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionreaderorcontextisnull.
TryDeserialize<T>(TextReader, T?, YamlSerializerOptions?)
YamlSerializer.csAttempts 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
readerTextReader- The source reader.
valueT?- The deserialized value when successful; otherwise
default. optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionreaderisnull.
TryDeserialize<T>(string, YamlSerializerContext, T?)
YamlSerializer.csAttempts 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
yamlstring- The YAML payload.
contextYamlSerializerContext- The source-generated serializer context.
valueT?- The deserialized value when successful; otherwise
default.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionyamlorcontextisnull.
TryDeserialize<T>(string, T?, YamlSerializerOptions?)
YamlSerializer.csAttempts 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
yamlstring- The YAML payload.
valueT?- The deserialized value when successful; otherwise
default. optionsYamlSerializerOptions?- The serializer options. If
null,YamlSerializerOptions.Defaultis used.
Returns
bool true when deserialization succeeded; otherwise false.
Exceptions
ArgumentNullExceptionyamlisnull.