YamlReaderWriterBase Class
Shared base class for YamlReader and YamlWriter.
public abstract class YamlReaderWriterBaseRemarks
This type centralizes option access and caches frequently computed values (naming policy conversions and converter resolution) to reduce repeated runtime work during serialization and deserialization.
Constructors
| Name | Description |
|---|---|
| YamlReaderWriterBase(YamlSerializerOptions) | Initializes a new instance of the YamlReaderWriterBase class. |
YamlReaderWriterBase(YamlSerializerOptions)
YamlReaderWriterBase.csInitializes a new instance of the YamlReaderWriterBase class.
protected YamlReaderWriterBase(YamlSerializerOptions options)Parameters
optionsYamlSerializerOptions- The options associated with this reader or writer.
Exceptions
ArgumentNullExceptionoptionsisnull.
Properties
| Name | Description |
|---|---|
| Options | Gets the options associated with this reader or writer instance. |
Options
YamlReaderWriterBase.csGets the options associated with this reader or writer instance.
public YamlSerializerOptions Options { get; }Property value
Methods
| Name | Description |
|---|---|
| ConvertDictionaryKey(string) | Converts a dictionary key into a YAML key using YamlSerializerOptions.DictionaryKeyPolicy. |
| ConvertName(string) | Converts a CLR member name into a YAML member name using YamlSerializerOptions.PropertyNamingPolicy. |
| GetConverter(Type) | Gets a converter that can handle typeToConvert. |
| TryGetCustomConverter(Type, YamlConverter?) | Attempts to resolve a custom converter for typeToConvert from YamlSerializerOptions.Converters. |
ConvertDictionaryKey(string)
YamlReaderWriterBase.csConverts a dictionary key into a YAML key using YamlSerializerOptions.DictionaryKeyPolicy.
Parameters
keystring- The dictionary key.
Returns
string The converted YAML key.
Exceptions
ArgumentNullExceptionkeyisnull.
ConvertName(string)
YamlReaderWriterBase.csConverts a CLR member name into a YAML member name using YamlSerializerOptions.PropertyNamingPolicy.
Parameters
namestring- The CLR member name.
Returns
string The converted YAML member name.
Exceptions
ArgumentNullExceptionnameisnull.
GetConverter(Type)
YamlReaderWriterBase.csGets a converter that can handle typeToConvert.
public YamlConverter GetConverter(Type typeToConvert)Parameters
typeToConvertType- The CLR type to resolve.
Returns
YamlConverter The converter for typeToConvert.
Exceptions
ArgumentNullExceptiontypeToConvertisnull.NotSupportedException- No converter can handle
typeToConvert.
TryGetCustomConverter(Type, YamlConverter?)
YamlReaderWriterBase.csAttempts to resolve a custom converter for typeToConvert from YamlSerializerOptions.Converters.
public bool TryGetCustomConverter(Type typeToConvert, out YamlConverter? converter)Parameters
typeToConvertType- The CLR type to resolve.
converterYamlConverter?- When successful, receives the converter instance.
Returns
bool true when a custom converter was resolved; otherwise false.
Exceptions
ArgumentNullExceptiontypeToConvertisnull.InvalidOperationException- A converter factory returned
nullor returned a converter that does not handletypeToConvert.