DefaultXmlConverter Class
Definition
- Namespace
- Cuemon.Xml.Serialization.Converters
- Assemblies
- Cuemon.Xml.dll
Provides a default way to convert objects to and from XML.
public sealed class DefaultXmlConverter : XmlConverter
- Inheritance
-
DefaultXmlConverter
- Inherited Members
Examples
The following example demonstrates how DefaultXmlConverter can serialize and deserialize a simple XML value.
using System;
using System.Collections.Generic;
using System.IO;
using Cuemon.Xml.Serialization;
using Cuemon.Xml.Serialization.Converters;
using System.Xml;
namespace MyApp.Examples;
public static class DefaultXmlConverterExample
{
public static void Demonstrate()
{
var converter = new DefaultXmlConverter(new XmlQualifiedEntity("String"), new List<XmlConverter>());
using var buffer = new MemoryStream();
using (var writer = XmlWriter.Create(buffer, new XmlWriterSettings { OmitXmlDeclaration = true }))
{
converter.WriteXml(writer, "Hello World");
}
buffer.Position = 0;
using var reader = XmlReader.Create(buffer);
var value = (string)converter.ReadXml(reader, typeof(string));
Console.WriteLine(value);
Console.WriteLine(converter.CanConvert(typeof(string)));
}
}
Constructors
| Name | Description |
|---|---|
| DefaultXmlConverter(XmlQualifiedEntity, IList<XmlConverter>) | Initializes a new instance of the DefaultXmlConverter class. |
Methods
| Name | Description |
|---|---|
| CanConvert(Type) | Determines whether this instance can convert the specified object type. |
| ReadXml(XmlReader, Type) | Generates an object from its XML representation. |
| WriteXml(XmlWriter, object, XmlQualifiedEntity) | Converts an object into its XML representation. |