Table of Contents

XmlFormatterOptions Class

Definition

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

Name Description
XmlFormatterOptions()

Initializes a new instance of the XmlFormatterOptions class.

Properties

Name Description
DefaultConverters

Gets or sets a delegate that is invoked when XmlFormatterOptions is initialized and propagates registered XmlConverter 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 XmlFormatter.

SupportedMediaTypes

Gets or sets the collection of MediaTypeHeaderValue elements supported by the XmlFormatter.

SynchronizeWithXmlConvert

Gets or sets a value indicating whether Settings should be synchronized on DefaultSettings.

Methods

Name Description
ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.