YamlFormatterOptions Class
Definition
- Namespace
- Codebelt.Extensions.YamlDotNet.Formatters
- Assemblies
- Codebelt.Extensions.YamlDotNet.dll
Configuration options for YamlFormatter.
public class YamlFormatterOptions : EncodingOptions, IEncodingOptions, IExceptionDescriptorOptions, IContentNegotiation, IValidatableParameterObject, IParameterObject
- Inheritance
-
YamlFormatterOptions
- Implements
- Inherited Members
- Extension Methods
Examples
The following example demonstrates how to configure YamlFormatterOptions to customize YAML serialization behavior, including converters, encoding, and fault sensitivity.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Codebelt.Extensions.YamlDotNet.Converters;
using Codebelt.Extensions.YamlDotNet.Formatters;
using Cuemon.Diagnostics;
namespace ExampleNamespace;
class Program
{
static void Main()
{
// Create options and configure defaults
var options = new YamlFormatterOptions
{
// Set encoding for output
Encoding = Encoding.UTF8,
// Configure which exception details to include
SensitivityDetails = FaultSensitivityDetails.FailureWithStackTrace | FaultSensitivityDetails.FailureWithData
};
// Add custom converters to the settings
options.Settings.Converters.AddFailureConverter();
// Use options to create a formatter
var formatter = new YamlFormatter(options);
// Now use the formatter for serialization
try
{
throw new InvalidOperationException("Example error");
}
catch (Exception ex)
{
var failure = new Failure(ex, FaultSensitivityDetails.FailureWithStackTrace | FaultSensitivityDetails.FailureWithData);
var yaml = formatter.Serialize(failure, typeof(Failure));
using (var reader = new StreamReader(yaml))
{
Console.WriteLine(reader.ReadToEnd());
}
}
}
}
Constructors
| Name | Description |
|---|---|
| YamlFormatterOptions() | Initializes a new instance of the YamlFormatterOptions class. |
Properties
| Name | Description |
|---|---|
| DefaultConverters | Gets or sets a delegate that is invoked when YamlFormatterOptions is initialized and propagates registered YamlConverter implementations. |
| DefaultMediaType | Provides the default/fallback media type that the associated formatter should use when content negotiation either fails or is absent. |
| SensitivityDetails | Gets or sets a bitwise combination of the enumeration values that specify which sensitive details to include in the serialized result. |
| Settings | Gets or sets the settings to support the YamlConverter. |
| SupportedMediaTypes | Gets or sets the collection of MediaTypeHeaderValue elements supported by the YamlFormatter. |
Methods
| Name | Description |
|---|---|
| ValidateOptions() | Determines whether the public read-write properties of this instance are in a valid state. |