YamlSerializer class
Provides functionality to serialize objects or value types to YAML and deserialize YAML into objects or value types.
Namespace: System.Text.Yaml ยท Assembly: Styml.dll
public static class YamlSerializer
Provides functionality to serialize objects or value types to YAML and deserialize YAML into objects or value types.
PropertiesLink to this heading
IsReflectionEnabledByDefaultLink to this heading
Indicates whether unconfigured YamlSerializerOptions instances should be set to use the reflection-based DefaultYamlTypeInfoResolver.
public static bool IsReflectionEnabledByDefault { get; }
The value of the property is backed by the "System.Text.Yaml.YamlSerializer.IsReflectionEnabledByDefault" AppContext setting and defaults to true if unset.
MethodsLink to this heading
DeserializeLink to this heading
Converts the YamlDocument representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(this YamlDocument document, YamlSerializerOptions? options = null);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
document: TheYamlDocumentto convert.options: Options to control the behavior during parsing.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | document is null. |
| YamlException | TValue is not compatible with the YAML. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the YamlDocument representing a single YAML value into a returnType.
public static object? Deserialize(this YamlDocument document, Type returnType, YamlSerializerOptions? options = null);
Parameters
document: TheYamlDocumentto convert.returnType: The type of the object to convert to and return.options: Options to control the behavior during parsing.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | document or returnType is null. |
| YamlException | returnType is not compatible with the YAML. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
Converts the YamlDocument representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(this YamlDocument document, YamlTypeInfo<TValue?> yamlTypeInfo);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
document: TheYamlDocumentto convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | document is null. -or- yamlTypeInfo is null. |
| YamlException | TValue is not compatible with the YAML. |
Converts the YamlDocument representing a single YAML value into an instance specified by the yamlTypeInfo.
public static object? Deserialize(this YamlDocument document, YamlTypeInfo yamlTypeInfo);
Parameters
document: TheYamlDocumentto convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | document is null. -or- yamlTypeInfo is null. |
Converts the YamlDocument representing a single YAML value into a returnType.
public static object? Deserialize(this YamlDocument document, Type returnType, YamlSerializerContext context);
Parameters
document: TheYamlDocumentto convert.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | document is null. -or- returnType is null. -or- context is null. |
| YamlException | The YAML is invalid. -or- returnType is not compatible with the YAML. -or- There is remaining data in the string beyond a single YAML value. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
Converts the YamlElement representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(this YamlElement element, YamlSerializerOptions? options = null);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
element: TheYamlElementto convert.options: Options to control the behavior during parsing.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | TValue is not compatible with the YAML. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the YamlElement representing a single YAML value into a returnType.
public static object? Deserialize(this YamlElement element, Type returnType, YamlSerializerOptions? options = null);
Parameters
element: TheYamlElementto convert.returnType: The type of the object to convert to and return.options: Options to control the behavior during parsing.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | returnType is null. |
| YamlException | returnType is not compatible with the YAML. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
Converts the YamlElement representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(this YamlElement element, YamlTypeInfo<TValue> yamlTypeInfo);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
element: TheYamlElementto convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
| YamlException | TValue is not compatible with the YAML. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the YamlElement representing a single YAML value into an instance specified by the yamlTypeInfo.
public static object? Deserialize(this YamlElement element, YamlTypeInfo yamlTypeInfo);
Parameters
element: TheYamlElementto convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
Converts the YamlElement representing a single YAML value into a returnType.
public static object? Deserialize(this YamlElement element, Type returnType, YamlSerializerContext context);
Parameters
element: TheYamlElementto convert.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | returnType is null. -or- context is null. |
| YamlException | The YAML is invalid. -or- returnType is not compatible with the YAML. -or- There is remaining data in the string beyond a single YAML value. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
Converts the YamlNode representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(this YamlNode? node, YamlSerializerOptions? options = null);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
node: TheYamlNodeto convert.options: Options to control the behavior during parsing.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | TValue is not compatible with the YAML. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the YamlNode representing a single YAML value into a returnType.
public static object? Deserialize(this YamlNode? node, Type returnType, YamlSerializerOptions? options = null);
Parameters
node: TheYamlNodeto convert.returnType: The type of the object to convert to and return.options: Options to control the behavior during parsing.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | returnType is not compatible with the YAML. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
Converts the YamlNode representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(this YamlNode? node, YamlTypeInfo<TValue> yamlTypeInfo);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
node: TheYamlNodeto convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
| YamlException | TValue is not compatible with the YAML. |
Converts the YamlNode representing a single YAML value into an instance specified by the yamlTypeInfo.
public static object? Deserialize(this YamlNode? node, YamlTypeInfo yamlTypeInfo);
Parameters
node: TheYamlNodeto convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
Converts the YamlNode representing a single YAML value into a returnType.
public static object? Deserialize(this YamlNode? node, Type returnType, YamlSerializerContext context);
Parameters
node: TheYamlNodeto convert.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | returnType is null. -or- context is null. |
| YamlException | The YAML is invalid. -or- returnType is not compatible with the YAML. -or- There is remaining data in the string beyond a single YAML value. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
Parses the UTF-8 encoded text representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(ReadOnlySpan<byte> utf8Yaml, YamlSerializerOptions? options = null);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
utf8Yaml: YAML text to parse.options: Options to control the behavior during parsing.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or when there is remaining data in the Stream. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Parses the UTF-8 encoded text representing a single YAML value into a returnType.
public static object? Deserialize(ReadOnlySpan<byte> utf8Yaml, Type returnType, YamlSerializerOptions? options = null);
Parameters
utf8Yaml: YAML text to parse.returnType: The type of the object to convert to and return.options: Options to control the behavior during parsing.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | returnType is null. |
| YamlException | The YAML is invalid, returnType is not compatible with the YAML, or when there is remaining data in the Stream. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
Parses the UTF-8 encoded text representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(ReadOnlySpan<byte> utf8Yaml, YamlTypeInfo<TValue> yamlTypeInfo);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
utf8Yaml: YAML text to parse.yamlTypeInfo: Metadata about the type to convert.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or when there is remaining data in the buffer. |
Parses the UTF-8 encoded text representing a single YAML value into an instance specified by the yamlTypeInfo.
public static object? Deserialize(ReadOnlySpan<byte> utf8Yaml, YamlTypeInfo yamlTypeInfo);
Parameters
utf8Yaml: YAML text to parse.yamlTypeInfo: Metadata about the type to convert.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | The YAML is invalid, or there is remaining data in the buffer. |
Parses the UTF-8 encoded text representing a single YAML value into a returnType.
public static object? Deserialize(ReadOnlySpan<byte> utf8Yaml, Type returnType, YamlSerializerContext context);
Parameters
utf8Yaml: YAML text to parse.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | returnType is null. |
| YamlException | The YAML is invalid, returnType is not compatible with the YAML, or when there is remaining data in the Stream. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method on the provided context did not return a compatible YamlTypeInfo for returnType. |
Reads the UTF-8 encoded text representing a single YAML value into a TValue. The Stream will be read to completion.
public static TValue? Deserialize<TValue>(Stream utf8Yaml, YamlSerializerOptions? options = null);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
utf8Yaml: YAML data to parse.options: Options to control the behavior during reading.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or when there is remaining data in the Stream. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Reads the UTF-8 encoded text representing a single YAML value into a returnType. The Stream will be read to completion.
public static object? Deserialize(Stream utf8Yaml, Type returnType, YamlSerializerOptions? options = null);
Parameters
utf8Yaml: YAML data to parse.returnType: The type of the object to convert to and return.options: Options to control the behavior during reading.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or returnType is null. |
| YamlException | The YAML is invalid, the returnType is not compatible with the YAML, or when there is remaining data in the Stream. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
Reads the UTF-8 encoded text representing a single YAML value into a TValue. The Stream will be read to completion.
public static TValue? Deserialize<TValue>(Stream utf8Yaml, YamlTypeInfo<TValue?> yamlTypeInfo);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the type to convert.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or when there is remaining data in the Stream. |
Reads the UTF-8 encoded text representing a single YAML value into an instance specified by the yamlTypeInfo. The Stream will be read to completion.
public static object? Deserialize(Stream utf8Yaml, YamlTypeInfo yamlTypeInfo);
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the type to convert.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
| YamlException | The YAML is invalid, or when there is remaining data in the Stream. |
Reads the UTF-8 encoded text representing a single YAML value into a returnType. The Stream will be read to completion.
public static object? Deserialize(Stream utf8Yaml, Type returnType, YamlSerializerContext context);
Parameters
utf8Yaml: YAML data to parse.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml, returnType, or context is null. |
| YamlException | The YAML is invalid, the returnType is not compatible with the YAML, or when there is remaining data in the Stream. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method on the provided context did not return a compatible YamlTypeInfo for returnType. |
Parses the text representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(string yaml, YamlSerializerOptions? options = null);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
yaml: YAML text to parse.options: Options to control the behavior during parsing.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yaml is null. |
| YamlException | The YAML is invalid. -or- TValue is not compatible with the YAML. -or- There is remaining data in the string beyond a single YAML value. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Parses the text representing a single YAML value into an instance of the type specified by a generic type parameter.
public static TValue? Deserialize<TValue>(ReadOnlySpan<char> yaml, YamlSerializerOptions? options = null);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
yaml: The YAML text to parse.options: Options to control the behavior during parsing.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | The YAML is invalid. -or- TValue is not compatible with the YAML. -or- There is remaining data in the span beyond a single YAML value. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Using a UTF-16 span is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Parses the text representing a single YAML value into a returnType.
public static object? Deserialize(string yaml, Type returnType, YamlSerializerOptions? options = null);
Parameters
yaml: YAML text to parse.returnType: The type of the object to convert to and return.options: Options to control the behavior during parsing.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yaml or returnType is null. |
| YamlException | The YAML is invalid. -or- returnType is not compatible with the YAML. -or- There is remaining data in the string beyond a single YAML value. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Parses the text representing a single YAML value into an instance of a specified type.
public static object? Deserialize(ReadOnlySpan<char> yaml, Type returnType, YamlSerializerOptions? options = null);
Parameters
yaml: The YAML text to parse.returnType: The type of the object to convert to and return.options: Options to control the behavior during parsing.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | returnType is null. |
| YamlException | The YAML is invalid. -or- returnType is not compatible with the YAML. -or- There is remaining data in the span beyond a single YAML value. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
Using a UTF-16 span is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Parses the text representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(string yaml, YamlTypeInfo<TValue?> yamlTypeInfo);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
yaml: YAML text to parse.yamlTypeInfo: Metadata about the type to convert.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yaml is null. -or- yamlTypeInfo is null. |
| YamlException | The YAML is invalid. -or- TValue is not compatible with the YAML. -or- There is remaining data in the string beyond a single YAML value. |
Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Parses the text representing a single YAML value into a TValue.
public static TValue? Deserialize<TValue>(ReadOnlySpan<char> yaml, YamlTypeInfo<TValue> yamlTypeInfo);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
yaml: YAML text to parse.yamlTypeInfo: Metadata about the type to convert.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yaml is null. -or- yamlTypeInfo is null. |
| YamlException | The YAML is invalid. -or- TValue is not compatible with the YAML. -or- There is remaining data in the string beyond a single YAML value. |
Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Parses the text representing a single YAML value into an instance specified by the yamlTypeInfo.
public static object? Deserialize(string yaml, YamlTypeInfo yamlTypeInfo);
Parameters
yaml: YAML text to parse.yamlTypeInfo: Metadata about the type to convert.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yaml is null. -or- yamlTypeInfo is null. |
| YamlException | The YAML is invalid. -or- There is remaining data in the string beyond a single YAML value. |
Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Parses the text representing a single YAML value into an instance specified by the yamlTypeInfo.
public static object? Deserialize(ReadOnlySpan<char> yaml, YamlTypeInfo yamlTypeInfo);
Parameters
yaml: YAML text to parse.yamlTypeInfo: Metadata about the type to convert.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
| YamlException | The YAML is invalid. -or- There is remaining data in the string beyond a single YAML value. |
Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Parses the text representing a single YAML value into a returnType.
public static object? Deserialize(string yaml, Type returnType, YamlSerializerContext context);
Parameters
yaml: YAML text to parse.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yaml or returnType is null. -or- context is null. |
| YamlException | The YAML is invalid. -or- returnType is not compatible with the YAML. -or- There is remaining data in the string beyond a single YAML value. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Parses the text representing a single YAML value into a returnType.
public static object? Deserialize(ReadOnlySpan<char> yaml, Type returnType, YamlSerializerContext context);
Parameters
yaml: YAML text to parse.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yaml or returnType is null. -or- context is null. |
| YamlException | The YAML is invalid. -or- returnType is not compatible with the YAML. -or- There is remaining data in the string beyond a single YAML value. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
Using a String is not as efficient as using the UTF-8 methods since the implementation natively uses UTF-8.
Reads one YAML value (including objects or arrays) from the provided reader into a TValue.
public static TValue? Deserialize<TValue>(ref Utf8YamlReader reader, YamlSerializerOptions? options = null);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
reader: The reader to read.options: Options to control the serializer behavior during reading.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or a value could not be read from the reader. |
| ArgumentException | reader is using unsupported options. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
If the Utf8YamlReader.TokenType property of reader is YamlTokenType.PropertyName or YamlTokenType.None, the reader will be advanced by one call to Utf8YamlReader.Read to determine the start of the value.
Upon completion of this method, reader will be positioned at the final token in the YAML value. If an exception is thrown, the reader is reset to the state it was in when the method was called.
This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.
The YamlReaderOptions used to create the instance of the Utf8YamlReader take precedence over the YamlSerializerOptions when they conflict. Hence, YamlReaderOptions.AllowTrailingCommas, YamlReaderOptions.MaxDepth, and YamlReaderOptions.CommentHandling are used while reading.
Reads one YAML value (including objects or arrays) from the provided reader into a returnType.
public static object? Deserialize(ref Utf8YamlReader reader, Type returnType, YamlSerializerOptions? options = null);
Parameters
reader: The reader to read.returnType: The type of the object to convert to and return.options: Options to control the serializer behavior during reading.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | returnType is null. |
| YamlException | The YAML is invalid, returnType is not compatible with the YAML, or a value could not be read from the reader. |
| ArgumentException | reader is using unsupported options. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
If the Utf8YamlReader.TokenType property of reader is YamlTokenType.PropertyName or YamlTokenType.None, the reader will be advanced by one call to Utf8YamlReader.Read to determine the start of the value.
Upon completion of this method, reader will be positioned at the final token in the YAML value. If an exception is thrown, the reader is reset to the state it was in when the method was called.
This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.
The YamlReaderOptions used to create the instance of the Utf8YamlReader take precedence over the YamlSerializerOptions when they conflict. Hence, YamlReaderOptions.AllowTrailingCommas, YamlReaderOptions.MaxDepth, and YamlReaderOptions.CommentHandling are used while reading.
Reads one YAML value (including objects or arrays) from the provided reader into a TValue.
public static TValue? Deserialize<TValue>(ref Utf8YamlReader reader, YamlTypeInfo<TValue> yamlTypeInfo);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
reader: The reader to read.yamlTypeInfo: Metadata about the type to convert.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or a value could not be read from the reader. |
| ArgumentException | reader is using unsupported options. |
If the Utf8YamlReader.TokenType property of reader is YamlTokenType.PropertyName or YamlTokenType.None, the reader will be advanced by one call to Utf8YamlReader.Read to determine the start of the value.
Upon completion of this method, reader will be positioned at the final token in the YAML value. If an exception is thrown, the reader is reset to the state it was in when the method was called.
This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.
The YamlReaderOptions used to create the instance of the Utf8YamlReader take precedence over the YamlSerializerOptions when they conflict. Hence, YamlReaderOptions.AllowTrailingCommas, YamlReaderOptions.MaxDepth, and YamlReaderOptions.CommentHandling are used while reading.
Reads one YAML value (including objects or arrays) from the provided reader into an instance specified by the yamlTypeInfo.
public static object? Deserialize(ref Utf8YamlReader reader, YamlTypeInfo yamlTypeInfo);
Parameters
reader: The reader to read.yamlTypeInfo: Metadata about the type to convert.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| YamlException | The YAML is invalid, yamlTypeInfo is not compatible with the YAML, or a value could not be read from the reader. |
| ArgumentException | reader is using unsupported options. |
If the Utf8YamlReader.TokenType property of reader is YamlTokenType.PropertyName or YamlTokenType.None, the reader will be advanced by one call to Utf8YamlReader.Read to determine the start of the value.
Upon completion of this method, reader will be positioned at the final token in the YAML value. If an exception is thrown, the reader is reset to the state it was in when the method was called.
This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.
The YamlReaderOptions used to create the instance of the Utf8YamlReader take precedence over the YamlSerializerOptions when they conflict. Hence, YamlReaderOptions.AllowTrailingCommas, YamlReaderOptions.MaxDepth, and YamlReaderOptions.CommentHandling are used while reading.
Reads one YAML value (including objects or arrays) from the provided reader into a returnType.
public static object? Deserialize(ref Utf8YamlReader reader, Type returnType, YamlSerializerContext context);
Parameters
reader: The reader to read.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | returnType or context is null. |
| YamlException | The YAML is invalid, returnType is not compatible with the YAML, or a value could not be read from the reader. |
| ArgumentException | reader is using unsupported options. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method on the provided context did not return a compatible YamlTypeInfo for returnType. |
If the Utf8YamlReader.TokenType property of reader is YamlTokenType.PropertyName or YamlTokenType.None, the reader will be advanced by one call to Utf8YamlReader.Read to determine the start of the value.
Upon completion of this method, reader will be positioned at the final token in the YAML value. If an exception is thrown, the reader is reset to the state it was in when the method was called.
This method makes a copy of the data the reader acted on, so there is no caller requirement to maintain data integrity beyond the return of this method.
The YamlReaderOptions used to create the instance of the Utf8YamlReader take precedence over the YamlSerializerOptions when they conflict. Hence, YamlReaderOptions.AllowTrailingCommas, YamlReaderOptions.MaxDepth, and YamlReaderOptions.CommentHandling are used while reading.
DeserializeAsyncLink to this heading
Reads the UTF-8 encoded text representing a single YAML value into a TValue. The PipeReader will be read to completion.
public static ValueTask<TValue?> DeserializeAsync<TValue>(PipeReader utf8Yaml, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
utf8Yaml: YAML data to parse.options: Options to control the behavior during reading.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or when there is remaining data in the PipeReader. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Reads the UTF-8 encoded text representing a single YAML value into a TValue. The PipeReader will be read to completion.
public static ValueTask<TValue?> DeserializeAsync<TValue>(PipeReader utf8Yaml, YamlTypeInfo<TValue?> yamlTypeInfo, CancellationToken cancellationToken = default);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or when there is remaining data in the PipeReader. |
Reads the UTF-8 encoded text representing a single YAML value into an instance specified by the yamlTypeInfo. The PipeReader will be read to completion.
public static ValueTask<object?> DeserializeAsync(PipeReader utf8Yaml, YamlTypeInfo yamlTypeInfo, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
| YamlException | The YAML is invalid, or when there is remaining data in the PipeReader. |
Reads the UTF-8 encoded text representing a single YAML value into a returnType. The PipeReader will be read to completion.
public static ValueTask<object?> DeserializeAsync(PipeReader utf8Yaml, Type returnType, YamlSerializerContext context, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: YAML data to parse.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml, returnType, or context is null. |
| YamlException | The YAML is invalid, the returnType is not compatible with the YAML, or when there is remaining data in the PipeReader. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method on the provided context did not return a compatible YamlTypeInfo for returnType. |
Reads the UTF-8 encoded text representing a single YAML value into a returnType. The PipeReader will be read to completion.
public static ValueTask<object?> DeserializeAsync(PipeReader utf8Yaml, Type returnType, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: YAML data to parse.returnType: The type of the object to convert to and return.options: Options to control the behavior during reading.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or returnType is null. |
| YamlException | The YAML is invalid, the returnType is not compatible with the YAML, or when there is remaining data in the PipeReader. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
Reads the UTF-8 encoded text representing a single YAML value into a TValue. The Stream will be read to completion.
public static ValueTask<TValue?> DeserializeAsync<TValue>(Stream utf8Yaml, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
utf8Yaml: YAML data to parse.options: Options to control the behavior during reading.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or when there is remaining data in the Stream. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Reads the UTF-8 encoded text representing a single YAML value into a returnType. The Stream will be read to completion.
public static ValueTask<object?> DeserializeAsync(Stream utf8Yaml, Type returnType, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: YAML data to parse.returnType: The type of the object to convert to and return.options: Options to control the behavior during reading.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or returnType is null. |
| YamlException | The YAML is invalid, the returnType is not compatible with the YAML, or when there is remaining data in the Stream. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
Reads the UTF-8 encoded text representing a single YAML value into a TValue. The Stream will be read to completion.
public static ValueTask<TValue?> DeserializeAsync<TValue>(Stream utf8Yaml, YamlTypeInfo<TValue?> yamlTypeInfo, CancellationToken cancellationToken = default);
Type parameters
TValue: The type to deserialize the YAML value into.
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A TValue representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
| YamlException | The YAML is invalid, TValue is not compatible with the YAML, or when there is remaining data in the Stream. |
Reads the UTF-8 encoded text representing a single YAML value into an instance specified by the yamlTypeInfo. The Stream will be read to completion.
public static ValueTask<object?> DeserializeAsync(Stream utf8Yaml, YamlTypeInfo yamlTypeInfo, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A yamlTypeInfo representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
| YamlException | The YAML is invalid, or when there is remaining data in the Stream. |
Reads the UTF-8 encoded text representing a single YAML value into a returnType. The Stream will be read to completion.
public static ValueTask<object?> DeserializeAsync(Stream utf8Yaml, Type returnType, YamlSerializerContext context, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: YAML data to parse.returnType: The type of the object to convert to and return.context: A metadata provider for serializable types.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: A returnType representation of the YAML value.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml, returnType, or context is null. |
| YamlException | The YAML is invalid, the returnType is not compatible with the YAML, or when there is remaining data in the Stream. |
| NotSupportedException | There is no compatible YamlConverter for returnType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method on the provided context did not return a compatible YamlTypeInfo for returnType. |
DeserializeAsyncEnumerableLink to this heading
Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize root-level YAML arrays in a streaming manner.
public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(PipeReader utf8Yaml, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The element type to deserialize asynchronously.
Parameters
utf8Yaml: YAML data to parse.options: Options to control the behavior during reading.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: An IAsyncEnumerable<T> representation of the provided YAML array.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize root-level YAML arrays in a streaming manner.
public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(PipeReader utf8Yaml, YamlTypeInfo<TValue?> yamlTypeInfo, CancellationToken cancellationToken = default);
Type parameters
TValue: The element type to deserialize asynchronously.
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the element type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: An IAsyncEnumerable<T> representation of the provided YAML array.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize sequences of YAML values in a streaming manner.
public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(PipeReader utf8Yaml, YamlTypeInfo<TValue?> yamlTypeInfo, bool topLevelValues, CancellationToken cancellationToken = default);
Type parameters
TValue: The element type to deserialize asynchronously.
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the element type to convert.topLevelValues:trueto deserialize from a sequence of top-level YAML values (for example, a JSON Lines (JSONL) document);falseto deserialize from a single top-level array.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: An IAsyncEnumerable<T> representation of the provided YAML sequence.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
When topLevelValues is set to true, treats the PipeReader as a sequence of whitespace separated top-level YAML values and attempts to deserialize each value into TValue. This is a superset of the JSON Lines (JSONL) format and can be used to consume valid JSONL documents. When topLevelValues is set to false, treats the PipeReader as a YAML array and attempts to deserialize each element into TValue.
Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize sequences of YAML values in a streaming manner.
public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(PipeReader utf8Yaml, bool topLevelValues, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The element type to deserialize asynchronously.
Parameters
utf8Yaml: YAML data to parse.topLevelValues:trueto deserialize from a sequence of top-level YAML values (for example, a JSON Lines (JSONL) document);falseto deserialize from a single top-level array.options: Options to control the behavior during reading.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: An IAsyncEnumerable<T> representation of the provided YAML sequence.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
When topLevelValues is set to true, treats the PipeReader as a sequence of whitespace separated top-level YAML values and attempts to deserialize each value into TValue. This is a superset of the JSON Lines (JSONL) format and can be used to consume valid JSONL documents. When topLevelValues is set to false, treats the PipeReader as a YAML array and attempts to deserialize each element into TValue.
Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize root-level YAML arrays in a streaming manner.
public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(Stream utf8Yaml, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The element type to deserialize asynchronously.
Parameters
utf8Yaml: YAML data to parse.options: Options to control the behavior during reading.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: An IAsyncEnumerable<T> representation of the provided YAML array.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize sequences of YAML values in a streaming manner.
public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(Stream utf8Yaml, bool topLevelValues, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The element type to deserialize asynchronously.
Parameters
utf8Yaml: YAML data to parse.topLevelValues:trueto deserialize from a sequence of top-level YAML values (for example, a JSON Lines (JSONL) document);falseto deserialize from a single top-level array.options: Options to control the behavior during reading.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: An IAsyncEnumerable<T> representation of the provided YAML sequence.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
When topLevelValues is set to true, treats the stream as a sequence of whitespace separated top-level YAML values and attempts to deserialize each value into TValue. This is a superset of the JSON Lines (JSONL) format and can be used to consume valid JSONL documents. When topLevelValues is set to false, treats the stream as a YAML array and attempts to deserialize each element into TValue.
Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize root-level YAML arrays in a streaming manner.
public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(Stream utf8Yaml, YamlTypeInfo<TValue?> yamlTypeInfo, CancellationToken cancellationToken = default);
Type parameters
TValue: The element type to deserialize asynchronously.
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the element type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: An IAsyncEnumerable<T> representation of the provided YAML array.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
Wraps the UTF-8 encoded text into an IAsyncEnumerable<T> that can be used to deserialize sequences of YAML values in a streaming manner.
public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(Stream utf8Yaml, YamlTypeInfo<TValue?> yamlTypeInfo, bool topLevelValues, CancellationToken cancellationToken = default);
Type parameters
TValue: The element type to deserialize asynchronously.
Parameters
utf8Yaml: YAML data to parse.yamlTypeInfo: Metadata about the element type to convert.topLevelValues:trueto deserialize from a sequence of top-level YAML values (for example, a JSON Lines (JSONL) document);falseto deserialize from a single top-level array.cancellationToken: TheCancellationTokenthat can be used to cancel the read operation.
Returns: An IAsyncEnumerable<T> representation of the provided YAML sequence.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or yamlTypeInfo is null. |
When topLevelValues is set to true, treats the stream as a sequence of whitespace separated top-level YAML values and attempts to deserialize each value into TValue. This is a superset of the JSON Lines (JSONL) format and can be used to consume valid JSONL documents. When topLevelValues is set to false, treats the stream as a YAML array and attempts to deserialize each element into TValue.
SerializeLink to this heading
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static void Serialize<TValue>(Stream utf8Yaml, TValue? value, YamlSerializerOptions? options = null);
Type parameters
TValue: The type of the value to serialize.
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.options: Options to control the conversion behavior.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static void Serialize(Stream utf8Yaml, object? value, Type inputType, YamlSerializerOptions? options = null);
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.inputType: The type of thevalueto convert.options: Options to control the conversion behavior.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | utf8Yaml or inputType is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static void Serialize<TValue>(Stream utf8Yaml, TValue? value, YamlTypeInfo<TValue?> yamlTypeInfo);
Type parameters
TValue: The type of the value to serialize.
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static void Serialize(Stream utf8Yaml, object? value, YamlTypeInfo yamlTypeInfo);
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
| InvalidCastException | value does not match the type of yamlTypeInfo. |
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static void Serialize(Stream utf8Yaml, object? value, Type inputType, YamlSerializerContext context);
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.inputType: The type of thevalueto convert.context: A metadata provider for serializable types.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | utf8Yaml, inputType, or context is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
Converts the provided value into a String.
public static string Serialize<TValue>(TValue? value, YamlSerializerOptions? options = null);
Type parameters
TValue: The type of the value to serialize.
Parameters
value: The value to convert.options: Options to control the conversion behavior.
Returns: A String representation of the value.
| Exception | Condition |
|---|---|
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Using a String is not as efficient as using UTF-8 encoding since the implementation internally uses UTF-8. See also YamlSerializer.SerializeToUtf8Bytes and YamlSerializer.SerializeAsync.
Converts the provided value into a String.
public static string Serialize(object? value, Type inputType, YamlSerializerOptions? options = null);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.options: Options to control the conversion behavior.
Returns: A String representation of the value.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
| ArgumentNullException | inputType is null. |
Using a String is not as efficient as using UTF-8 encoding since the implementation internally uses UTF-8. See also YamlSerializer.SerializeToUtf8Bytes and YamlSerializer.SerializeAsync.
Converts the provided value into a String.
public static string Serialize<TValue>(TValue? value, YamlTypeInfo<TValue?> yamlTypeInfo);
Type parameters
TValue: The type of the value to serialize.
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A String representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
Using a String is not as efficient as using UTF-8 encoding since the implementation internally uses UTF-8. See also YamlSerializer.SerializeToUtf8Bytes and YamlSerializer.SerializeAsync.
Converts the provided value into a String.
public static string Serialize(object? value, YamlTypeInfo yamlTypeInfo);
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A String representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
| InvalidCastException | value does not match the type of yamlTypeInfo. |
Using a String is not as efficient as using UTF-8 encoding since the implementation internally uses UTF-8. See also YamlSerializer.SerializeToUtf8Bytes and YamlSerializer.SerializeAsync.
Converts the provided value into a String.
public static string Serialize(object? value, Type inputType, YamlSerializerContext context);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.context: A metadata provider for serializable types.
Returns: A String representation of the value.
| Exception | Condition |
|---|---|
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
| ArgumentNullException | inputType or context is null. |
Using a String is not as efficient as using UTF-8 encoding since the implementation internally uses UTF-8. See also YamlSerializer.SerializeToUtf8Bytes and YamlSerializer.SerializeAsync.
Writes one YAML value (including objects or arrays) to the provided writer.
public static void Serialize<TValue>(Utf8YamlWriter writer, TValue? value, YamlSerializerOptions? options = null);
Type parameters
TValue: The type of the value to serialize.
Parameters
writer: The writer to write.value: The value to convert and write.options: Options to control the behavior.
| Exception | Condition |
|---|---|
| ArgumentNullException | writer is null. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Writes one YAML value (including objects or arrays) to the provided writer.
public static void Serialize(Utf8YamlWriter writer, object? value, Type inputType, YamlSerializerOptions? options = null);
Parameters
writer:value: The value to convert and write.inputType: The type of thevalueto convert.options: Options to control the behavior.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | writer or inputType is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
Writes one YAML value (including objects or arrays) to the provided writer.
public static void Serialize<TValue>(Utf8YamlWriter writer, TValue? value, YamlTypeInfo<TValue?> yamlTypeInfo);
Type parameters
TValue: The type of the value to serialize.
Parameters
writer: The writer to write.value: The value to convert and write.yamlTypeInfo: Metadata about the type to convert.
| Exception | Condition |
|---|---|
| ArgumentNullException | writer or yamlTypeInfo is null. |
Writes one YAML value (including objects or arrays) to the provided writer.
public static void Serialize(Utf8YamlWriter writer, object? value, YamlTypeInfo yamlTypeInfo);
Parameters
writer: The writer to write.value: The value to convert and write.yamlTypeInfo: Metadata about the type to convert.
| Exception | Condition |
|---|---|
| ArgumentNullException | writer or yamlTypeInfo is null. |
| InvalidCastException | value does not match the type of yamlTypeInfo. |
Writes one YAML value (including objects or arrays) to the provided writer.
public static void Serialize(Utf8YamlWriter writer, object? value, Type inputType, YamlSerializerContext context);
Parameters
writer:value: The value to convert and write.inputType: The type of thevalueto convert.context: A metadata provider for serializable types.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | writer or inputType is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
SerializeAsyncLink to this heading
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static Task SerializeAsync<TValue>(Stream utf8Yaml, TValue? value, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The type of the value to serialize.
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.options: Options to control the conversion behavior.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static Task SerializeAsync(Stream utf8Yaml, object? value, Type inputType, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.inputType: The type of thevalueto convert.options: Options to control the conversion behavior.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | utf8Yaml or inputType is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static Task SerializeAsync<TValue>(Stream utf8Yaml, TValue? value, YamlTypeInfo<TValue?> yamlTypeInfo, CancellationToken cancellationToken = default);
Type parameters
TValue: The type of the value to serialize.
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.yamlTypeInfo: Metadata about the type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static Task SerializeAsync(Stream utf8Yaml, object? value, YamlTypeInfo yamlTypeInfo, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.yamlTypeInfo: Metadata about the type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
| InvalidCastException | value does not match the type of yamlTypeInfo. |
Converts the provided value to UTF-8 encoded YAML text and write it to the Stream.
public static Task SerializeAsync(Stream utf8Yaml, object? value, Type inputType, YamlSerializerContext context, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: The UTF-8Streamto write to.value: The value to convert.inputType: The type of thevalueto convert.context: A metadata provider for serializable types.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | utf8Yaml, inputType, or context is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
Converts the provided value to UTF-8 encoded YAML text and write it to the PipeWriter.
public static Task SerializeAsync<TValue>(PipeWriter utf8Yaml, TValue? value, YamlTypeInfo<TValue?> yamlTypeInfo, CancellationToken cancellationToken = default);
Type parameters
TValue: The type of the value to serialize.
Parameters
utf8Yaml: The UTF-8PipeWriterto write to.value: The value to convert.yamlTypeInfo: Metadata about the type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
Converts the provided value to UTF-8 encoded YAML text and write it to the PipeWriter.
public static Task SerializeAsync<TValue>(PipeWriter utf8Yaml, TValue? value, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The type of the value to serialize.
Parameters
utf8Yaml: The UTF-8PipeWriterto write to.value: The value to convert.options: Options to control the conversion behavior.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the provided value to UTF-8 encoded YAML text and write it to the PipeWriter.
public static Task SerializeAsync(PipeWriter utf8Yaml, object? value, YamlTypeInfo yamlTypeInfo, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: The UTF-8PipeWriterto write to.value: The value to convert.yamlTypeInfo: Metadata about the type to convert.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml is null. |
| InvalidCastException | value does not match the type of yamlTypeInfo. |
Converts the provided value to UTF-8 encoded YAML text and write it to the PipeWriter.
public static Task SerializeAsync(PipeWriter utf8Yaml, object? value, Type inputType, YamlSerializerContext context, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: The UTF-8PipeWriterto write to.value: The value to convert.inputType: The type of thevalueto convert.context: A metadata provider for serializable types.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | utf8Yaml, inputType, or context is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
Converts the provided value to UTF-8 encoded YAML text and write it to the PipeWriter.
public static Task SerializeAsync(PipeWriter utf8Yaml, object? value, Type inputType, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Parameters
utf8Yaml: The UTF-8PipeWriterto write to.value: The value to convert.inputType: The type of thevalueto convert.options: Options to control the conversion behavior.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | utf8Yaml or inputType is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
SerializeAsyncEnumerableLink to this heading
Serializes each element of an IAsyncEnumerable<T> to the Stream in a streaming manner.
public static Task SerializeAsyncEnumerable<TValue>(Stream utf8Yaml, IAsyncEnumerable<TValue?> value, bool topLevelValues = false, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The type of elements in the sequence to serialize.
Parameters
utf8Yaml: The UTF-8Streamto write to.value: TheIAsyncEnumerable<T>sequence to serialize.topLevelValues:trueto serialize the elements as a sequence of newline-separated top-level YAML values (a JSON Lines (JSONL) document);falseto serialize them as a single root-level YAML array.options: Options to control the serialization behavior.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or value is null. |
When topLevelValues is true, the output conforms to the JSON Lines (JSONL) specification: each element is serialized as a single-line YAML value followed by a line-feed (\n) terminator. The line terminator is always \n regardless of YamlSerializerOptions.NewLine, and YamlSerializerOptions.WriteIndented is ignored so that each value is emitted on a single line.
Serializes each element of an IAsyncEnumerable<T> to the Stream in a streaming manner.
public static Task SerializeAsyncEnumerable<TValue>(Stream utf8Yaml, IAsyncEnumerable<TValue?> value, YamlTypeInfo<TValue?> yamlTypeInfo, bool topLevelValues = false, CancellationToken cancellationToken = default);
Type parameters
TValue: The type of elements in the sequence to serialize.
Parameters
utf8Yaml: The UTF-8Streamto write to.value: TheIAsyncEnumerable<T>sequence to serialize.yamlTypeInfo: Metadata about the type of elements to serialize.topLevelValues:trueto serialize the elements as a sequence of newline-separated top-level YAML values (a JSON Lines (JSONL) document);falseto serialize them as a single root-level YAML array.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml, value, or yamlTypeInfo is null. |
When topLevelValues is true, the output conforms to the JSON Lines (JSONL) specification: each element is serialized as a single-line YAML value followed by a line-feed (\n) terminator. The line terminator is always \n regardless of YamlSerializerOptions.NewLine, and YamlSerializerOptions.WriteIndented is ignored so that each value is emitted on a single line.
Serializes each element of an IAsyncEnumerable<T> to the PipeWriter in a streaming manner.
public static Task SerializeAsyncEnumerable<TValue>(PipeWriter utf8Yaml, IAsyncEnumerable<TValue?> value, bool topLevelValues = false, YamlSerializerOptions? options = null, CancellationToken cancellationToken = default);
Type parameters
TValue: The type of elements in the sequence to serialize.
Parameters
utf8Yaml: ThePipeWriterto write to.value: TheIAsyncEnumerable<T>sequence to serialize.topLevelValues:trueto serialize the elements as a sequence of newline-separated top-level YAML values (a JSON Lines (JSONL) document);falseto serialize them as a single root-level YAML array.options: Options to control the serialization behavior.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml or value is null. |
When topLevelValues is true, the output conforms to the JSON Lines (JSONL) specification: each element is serialized as a single-line YAML value followed by a line-feed (\n) terminator. The line terminator is always \n regardless of YamlSerializerOptions.NewLine, and YamlSerializerOptions.WriteIndented is ignored so that each value is emitted on a single line.
Serializes each element of an IAsyncEnumerable<T> to the PipeWriter in a streaming manner.
public static Task SerializeAsyncEnumerable<TValue>(PipeWriter utf8Yaml, IAsyncEnumerable<TValue?> value, YamlTypeInfo<TValue?> yamlTypeInfo, bool topLevelValues = false, CancellationToken cancellationToken = default);
Type parameters
TValue: The type of elements in the sequence to serialize.
Parameters
utf8Yaml: ThePipeWriterto write to.value: TheIAsyncEnumerable<T>sequence to serialize.yamlTypeInfo: Metadata about the type of elements to serialize.topLevelValues:trueto serialize the elements as a sequence of newline-separated top-level YAML values (a JSON Lines (JSONL) document);falseto serialize them as a single root-level YAML array.cancellationToken: TheCancellationTokenthat can be used to cancel the write operation.
Returns: A task that represents the asynchronous write operation.
| Exception | Condition |
|---|---|
| ArgumentNullException | utf8Yaml, value, or yamlTypeInfo is null. |
When topLevelValues is true, the output conforms to the JSON Lines (JSONL) specification: each element is serialized as a single-line YAML value followed by a line-feed (\n) terminator. The line terminator is always \n regardless of YamlSerializerOptions.NewLine, and YamlSerializerOptions.WriteIndented is ignored so that each value is emitted on a single line.
SerializeToDocumentLink to this heading
Converts the provided value into a YamlDocument.
public static YamlDocument SerializeToDocument<TValue>(TValue? value, YamlSerializerOptions? options = null);
Type parameters
TValue: The type of the value to serialize.
Parameters
value: The value to convert.options: Options to control the conversion behavior.
Returns: A YamlDocument representation of the YAML value.
| Exception | Condition |
|---|---|
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the provided value into a YamlDocument.
public static YamlDocument SerializeToDocument(object? value, Type inputType, YamlSerializerOptions? options = null);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.options: Options to control the conversion behavior.
Returns: A YamlDocument representation of the value.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| NotSupportedException | inputType is null. There is no compatible YamlConverter for inputType or its serializable members. |
Converts the provided value into a YamlDocument.
public static YamlDocument SerializeToDocument<TValue>(TValue? value, YamlTypeInfo<TValue?> yamlTypeInfo);
Type parameters
TValue: The type of the value to serialize.
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A YamlDocument representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
Converts the provided value into a YamlDocument.
public static YamlDocument SerializeToDocument(object? value, YamlTypeInfo yamlTypeInfo);
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A YamlDocument representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
| InvalidCastException | value does not match the type of yamlTypeInfo. |
Converts the provided value into a YamlDocument.
public static YamlDocument SerializeToDocument(object? value, Type inputType, YamlSerializerContext context);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.context: A metadata provider for serializable types.
Returns: A YamlDocument representation of the value.
| Exception | Condition |
|---|---|
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
| ArgumentNullException | inputType or context is null. |
SerializeToElementLink to this heading
Converts the provided value into a YamlElement.
public static YamlElement SerializeToElement<TValue>(TValue value, YamlSerializerOptions? options = null);
Type parameters
TValue: The type of the value to serialize.
Parameters
value: The value to convert.options: Options to control the conversion behavior.
Returns: A YamlElement representation of the YAML value.
| Exception | Condition |
|---|---|
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the provided value into a YamlElement.
public static YamlElement SerializeToElement(object? value, Type inputType, YamlSerializerOptions? options = null);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.options: Options to control the conversion behavior.
Returns: A YamlElement representation of the value.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| NotSupportedException | inputType is null. There is no compatible YamlConverter for inputType or its serializable members. |
Converts the provided value into a YamlElement.
public static YamlElement SerializeToElement<TValue>(TValue? value, YamlTypeInfo<TValue?> yamlTypeInfo);
Type parameters
TValue: The type of the value to serialize.
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A YamlElement representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
Converts the provided value into a YamlElement.
public static YamlElement SerializeToElement(object? value, YamlTypeInfo yamlTypeInfo);
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A YamlElement representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
| InvalidCastException | value does not match the type of yamlTypeInfo. |
Converts the provided value into a YamlElement.
public static YamlElement SerializeToElement(object? value, Type inputType, YamlSerializerContext context);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.context: A metadata provider for serializable types.
Returns: A YamlElement representation of the value.
| Exception | Condition |
|---|---|
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
| ArgumentNullException | inputType or context is null. |
SerializeToNodeLink to this heading
Converts the provided value into a YamlNode.
public static YamlNode? SerializeToNode<TValue>(TValue value, YamlSerializerOptions? options = null);
Type parameters
TValue: The type of the value to serialize.
Parameters
value: The value to convert.options: Options to control the conversion behavior.
Returns: A YamlNode representation of the YAML value.
| Exception | Condition |
|---|---|
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the provided value into a YamlNode.
public static YamlNode? SerializeToNode(object? value, Type inputType, YamlSerializerOptions? options = null);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.options: Options to control the conversion behavior.
Returns: A YamlNode representation of the value.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| NotSupportedException | inputType is null. There is no compatible YamlConverter for inputType or its serializable members. |
Converts the provided value into a YamlNode.
public static YamlNode? SerializeToNode<TValue>(TValue? value, YamlTypeInfo<TValue?> yamlTypeInfo);
Type parameters
TValue: The type of the value to serialize.
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A YamlNode representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
Converts the provided value into a YamlNode.
public static YamlNode? SerializeToNode(object? value, YamlTypeInfo yamlTypeInfo);
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A YamlNode representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
| InvalidCastException | value does not match the type of yamlTypeInfo. |
Converts the provided value into a YamlNode.
public static YamlNode? SerializeToNode(object? value, Type inputType, YamlSerializerContext context);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.context: A metadata provider for serializable types.
Returns: A YamlNode representation of the value.
| Exception | Condition |
|---|---|
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |
| ArgumentNullException | inputType or context is null. |
SerializeToUtf8BytesLink to this heading
Converts the provided value into a Byte array.
public static byte[] SerializeToUtf8Bytes<TValue>(TValue? value, YamlSerializerOptions? options = null);
Parameters
value: The value to convert.options: Options to control the conversion behavior.
Returns: A UTF-8 representation of the value.
| Exception | Condition |
|---|---|
| NotSupportedException | There is no compatible YamlConverter for TValue or its serializable members. |
Converts the provided value into a Byte array.
public static byte[] SerializeToUtf8Bytes(object? value, Type inputType, YamlSerializerOptions? options = null);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.options: Options to control the conversion behavior.
Returns: A UTF-8 representation of the value.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | inputType is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
Converts the provided value into a Byte array.
public static byte[] SerializeToUtf8Bytes<TValue>(TValue? value, YamlTypeInfo<TValue?> yamlTypeInfo);
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A UTF-8 representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
Converts the provided value into a Byte array.
public static byte[] SerializeToUtf8Bytes(object? value, YamlTypeInfo yamlTypeInfo);
Parameters
value: The value to convert.yamlTypeInfo: Metadata about the type to convert.
Returns: A UTF-8 representation of the value.
| Exception | Condition |
|---|---|
| ArgumentNullException | yamlTypeInfo is null. |
| InvalidCastException | value does not match the type of yamlTypeInfo. |
Converts the provided value into a Byte array.
public static byte[] SerializeToUtf8Bytes(object? value, Type inputType, YamlSerializerContext context);
Parameters
value: The value to convert.inputType: The type of thevalueto convert.context: A metadata provider for serializable types.
Returns: A UTF-8 representation of the value.
| Exception | Condition |
|---|---|
| ArgumentException | inputType is not compatible with value. |
| ArgumentNullException | inputType is null. |
| NotSupportedException | There is no compatible YamlConverter for inputType or its serializable members. |
| InvalidOperationException | The YamlSerializerContext.GetTypeInfo method of the provided context returns null for the type to convert. |