XmlFormatter Class
Definition
- Namespace
- Cuemon.Xml.Serialization.Formatters
- Assemblies
- Cuemon.Xml.dll
Serializes and deserializes an object in XML format.
public class XmlFormatter : StreamFormatter<XmlFormatterOptions>, IConfigurable<XmlFormatterOptions>
- Inheritance
-
objectXmlFormatter
- Implements
- Inherited Members
Examples
The following example demonstrates how to serialize an object with
using System;
using System.IO;
using Cuemon.Xml.Serialization.Formatters;
namespace MyApp.Examples;
public static class XmlFormatterExample
{
public static void Demonstrate()
{
var formatter = new XmlFormatter();
var person = new Person { Name = "John Doe", Age = 42 };
using var stream = formatter.Serialize(person, typeof(Person));
stream.Position = 0;
using var reader = new StreamReader(stream);
var xml = reader.ReadToEnd();
Console.WriteLine(xml.Contains("John Doe"));
Console.WriteLine(xml.Contains("42"));
}
private sealed class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
}
Constructors
| Name | Description |
|---|---|
| XmlFormatter() | Initializes a new instance of the XmlFormatter class. |
| XmlFormatter(XmlFormatterOptions) | Initializes a new instance of the XmlFormatter class. |
| XmlFormatter(Action<XmlFormatterOptions>) | Initializes a new instance of the XmlFormatter class. |
Methods
| Name | Description |
|---|---|
| Deserialize(Stream, Type) | Deserializes the specified |
| Serialize(object, Type) | Serializes the specified |
| SerializeToWriter(XmlWriter, object, Type) | Serializes the specified |
See Also
Formatter<TFormat>