Table of Contents

Class XmlConvert

Namespace
Cuemon.Xml.Serialization
Assembly
Cuemon.Xml.dll

Provides methods for converting between .NET types and XML types.

public static class XmlConvert
Inheritance
XmlConvert

Examples

The following example configures default XmlSerializerOptions on XmlConvert with UTF-8 encoding and tab indentation, then reads back the defaults and prints the encoding name. This demonstrates how to override global XML serialization settings.

using System;
using System.Text;
using System.Xml;
using Cuemon.Xml.Serialization;

namespace Cuemon.Xml.Serialization;

public class XmlConvertExample
{
    public void Demonstrate()
    {
        XmlConvert.DefaultSettings = () => new XmlSerializerOptions
        {
            Writer = new XmlWriterSettings { Encoding = Encoding.UTF8, IndentChars = Cuemon.Alphanumeric.Tab }
        };

        var settings = XmlConvert.DefaultSettings();
        Console.WriteLine($"Default encoding: {settings.Writer.Encoding.EncodingName}");
    }
}

Properties

DefaultSettings

Gets or sets a function delegate that creates default XmlSerializerOptions.

public static Func<XmlSerializerOptions> DefaultSettings { get; set; }

Property Value

Func<XmlSerializerOptions>

The function delegate which provides default settings for XmlConvert implementations.