Table of Contents

XmlConverterExtensions Class

Definition

Extension methods for the XmlConverter class.

public static class XmlConverterExtensions
Inheritance
XmlConverterExtensions

Examples

The following example demonstrates how to register ASP.NET Core-friendly XML converters on an instance.

using System;
using System.Collections.Generic;
using Cuemon.Diagnostics;
using Cuemon.Extensions.AspNetCore.Xml.Converters;
using Cuemon.Xml.Serialization.Converters;
using Cuemon.Xml.Serialization;

namespace MyApp.Examples
{
public static class XmlConverterExtensionsExample
{
    public static void Demonstrate()
    {
        var converters = new List<XmlConverter>();
        converters.AddProblemDetailsConverter();
        converters.AddHttpExceptionDescriptorConverter(options =>
        {
            options.SensitivityDetails = FaultSensitivityDetails.All;
        });
        converters.AddStringValuesConverter();
        converters.AddHeaderDictionaryConverter();
        converters.AddQueryCollectionConverter();
        converters.AddFormCollectionConverter();
        converters.AddCookieCollectionConverter();

        var serializerOptions = new XmlSerializerOptions();
        foreach (var converter in converters)
        {
            serializerOptions.Converters.Add(converter);
        }

        Console.WriteLine(serializerOptions.Converters.Count);
        Console.WriteLine(serializerOptions.Converters[0].CanConvert(typeof(object)));
    }
}
}

Methods

Name Description
AddCookieCollectionConverter(IList<XmlConverter>)

Adds an IRequestCookieCollection XML converter to the list.

AddFormCollectionConverter(IList<XmlConverter>)

Adds an IFormCollection XML converter to the list.

AddHeaderDictionaryConverter(IList<XmlConverter>)

Adds an IHeaderDictionary XML converter to the list.

AddHttpExceptionDescriptorConverter(IList<XmlConverter>, Action<ExceptionDescriptorOptions>)

Adds an ExceptionDescriptor XML converter to the list.

AddProblemDetailsConverter(IList<XmlConverter>)

Adds a ProblemDetails XML converter to the list.

AddQueryCollectionConverter(IList<XmlConverter>)

Adds an IQueryCollection XML converter to the list.

AddStringValuesConverter(IList<XmlConverter>)

Adds an StringValues XML converter to the list.