StreamDecoratorExtensions Class
Definition
- Assemblies
- Cuemon.Xml.dll
Extension methods for the Stream class hidden behind the IDecorator<T> interface.
public static class StreamDecoratorExtensions
- Inheritance
-
objectStreamDecoratorExtensions
Examples
The following example demonstrates how to create an
using System;
using System.IO;
using System.Text;
using System.Xml;
using Cuemon;
using Cuemon.Xml;
namespace MyApp.Examples;
public static class StreamDecoratorExtensionsExample
{
public static void Demonstrate()
{
const string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><root><child>hello</child></root>";
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
using XmlReader reader = Decorator.Enclose(stream).ToXmlReader();
reader.MoveToContent();
Console.WriteLine(reader.LocalName);
using var detectStream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
var detected = Decorator.Enclose(detectStream).TryDetectXmlEncoding(out var encoding);
Console.WriteLine(detected);
Console.WriteLine(encoding.EncodingName);
}
}
Methods
| Name | Description |
|---|---|
| ToXmlReader(IDecorator<Stream>, Encoding, Action<XmlReaderSettings>) | Converts the enclosed Stream of the specified |
| TryDetectXmlEncoding(IDecorator<Stream>, out Encoding) | Tries to resolve the Encoding level of the XML document from the enclosed Stream of the specified |
See Also
IDecorator<T>
Decorator<T>