Class XmlFormatterOptions
- Namespace
- Cuemon.Xml.Serialization.Formatters
- Assembly
- Cuemon.Xml.dll
Configuration options for XmlFormatter.
public class XmlFormatterOptions : IExceptionDescriptorOptions, IContentNegotiation, IValidatableParameterObject, IParameterObject
- Inheritance
-
XmlFormatterOptions
- Implements
Examples
The following example demonstrates how to configure XmlFormatterOptions for custom media types, fault sensitivity details, and synchronization with XmlConvert settings.
using System;
using System.Collections.Generic;
using System.Net.Http.Headers;
using Cuemon.Diagnostics;
using Cuemon.Xml.Serialization.Formatters;
namespace MyApp.Examples
{
public class XmlFormatterOptionsExample
{
public void Demonstrate()
{
// Configure XmlFormatter with custom settings.
var options = new XmlFormatterOptions
{
SynchronizeWithXmlConvert = true,
SensitivityDetails = FaultSensitivityDetails.None
};
// Customize the supported media types.
options.SupportedMediaTypes = new List<MediaTypeHeaderValue>
{
XmlFormatterOptions.DefaultMediaType,
new MediaTypeHeaderValue("text/xml"),
new MediaTypeHeaderValue("application/problem+xml")
};
Console.WriteLine($"Default media type: {XmlFormatterOptions.DefaultMediaType}"); // application/xml
Console.WriteLine($"Supported types: {options.SupportedMediaTypes.Count}"); // 3
Console.WriteLine($"Synchronize: {options.SynchronizeWithXmlConvert}"); // True
// Validate before use.
options.ValidateOptions();
Console.WriteLine("Options are valid.");
// Use with a formatter.
var formatter = new XmlFormatter(options);
Console.WriteLine($"Formatter created with {formatter.GetType().Name}.");
}}
}
Constructors
XmlFormatterOptions()
Initializes a new instance of the XmlFormatterOptions class.
public XmlFormatterOptions()
Remarks
The following table shows the initial property values for an instance of XmlFormatterOptions.
| Property | Initial Value |
|---|---|
| Settings | XmlSerializerOptions |
| SynchronizeWithXmlConvert | true |
| SensitivityDetails | None |
| SupportedMediaTypes |
|
Properties
DefaultConverters
Gets or sets a delegate that is invoked when XmlFormatterOptions is initialized and propagates registered XmlConverter implementations.
public static Action<IList<XmlConverter>> DefaultConverters { get; set; }
Property Value
- Action<IList<XmlConverter>>
The delegate which propagates registered XmlConverter implementations when XmlFormatterOptions is initialized.
DefaultMediaType
Provides the default/fallback media type that the associated formatter should use when content negotiation either fails or is absent.
public static MediaTypeHeaderValue DefaultMediaType { get; }
Property Value
- MediaTypeHeaderValue
The 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.
public FaultSensitivityDetails SensitivityDetails { get; set; }
Property Value
- FaultSensitivityDetails
The enumeration values that specify which sensitive details to include in the serialized result.
Settings
Gets or sets the settings to support the XmlFormatter.
public XmlSerializerOptions Settings { get; set; }
Property Value
- XmlSerializerOptions
A XmlSerializerOptions instance that specifies a set of features to support the XmlFormatter object.
SupportedMediaTypes
Gets or sets the collection of MediaTypeHeaderValue elements supported by the XmlFormatter.
public IReadOnlyCollection<MediaTypeHeaderValue> SupportedMediaTypes { get; set; }
Property Value
- IReadOnlyCollection<MediaTypeHeaderValue>
A collection of MediaTypeHeaderValue elements supported by the XmlFormatter.
SynchronizeWithXmlConvert
Gets or sets a value indicating whether Settings should be synchronized on DefaultSettings.
public bool SynchronizeWithXmlConvert { get; set; }
Property Value
- bool
trueif Settings should be synchronized on DefaultSettings; otherwise,false.
Methods
ValidateOptions()
Determines whether the public read-write properties of this instance are in a valid state.
public void ValidateOptions()
Remarks
This method is expected to throw exceptions when one or more conditions fails to be in a valid state.
Exceptions
- InvalidOperationException
Settings cannot be null.