Class StreamExtensions
- Namespace
- Cuemon.Extensions.Xml
- Assembly
- Cuemon.Extensions.Xml.dll
Extension methods for the System.IO.Stream class.
public static class StreamExtensions
- Inheritance
-
ObjectStreamExtensions
Methods
CopyXmlStream(Stream, Action<XmlWriterSettings>)
Copies the entire XML System.IO.Stream following the output format of setup
.
public static Stream CopyXmlStream(this Stream value, Action<XmlWriterSettings> setup = null)
Parameters
value
StreamThe XML System.IO.Stream to extend.
setup
Action<XmlWriterSettings>The System.Xml.XmlWriterSettings which may be configured.
Returns
- Stream
A System.IO.Stream that is equivalent to
value
following the output format ofsetup
.
Exceptions
- System.ArgumentNullException
value
cannot be null.
RemoveXmlNamespaceDeclarations(Stream, Action<XmlWriterSettings>)
Remove the XML namespace declarations from the specified value
.
public static Stream RemoveXmlNamespaceDeclarations(this Stream value, Action<XmlWriterSettings> setup = null)
Parameters
value
StreamThe XML System.IO.Stream to extend.
setup
Action<XmlWriterSettings>The System.Xml.XmlWriterSettings which may be configured.
Returns
- Stream
A System.IO.Stream object representing the specified
value
, but with no namespace declarations.
ToXmlReader(Stream, Encoding, Action<XmlReaderSettings>)
Converts the given value
to an System.Xml.XmlReader.
public static XmlReader ToXmlReader(this Stream value, Encoding encoding = null, Action<XmlReaderSettings> setup = null)
Parameters
value
StreamThe XML System.IO.Stream to extend.
encoding
EncodingThe text encoding to use.
setup
Action<XmlReaderSettings>The System.Xml.XmlReaderSettings which may be configured.
Returns
- XmlReader
An System.Xml.XmlReader representation of
value
.
Remarks
If encoding
is null, an System.Text.Encoding object will be attempted resolved by TryDetectXmlEncoding(Stream, out Encoding).
Exceptions
- System.ArgumentNullException
value
cannot be null.
TryDetectXmlEncoding(Stream, out Encoding)
Tries to resolve the System.Text.Encoding level of the XML document from the System.IO.Stream.
public static bool TryDetectXmlEncoding(this Stream value, out Encoding result)
Parameters
value
StreamThe XML System.IO.Stream to extend.
result
EncodingWhen this method returns, it contains the System.Text.Encoding value equivalent to the encoding level of the XML document contained in
value
, if the conversion succeeded, or a null reference (Nothing in Visual Basic) if the conversion failed. The conversion fails if thevalue
parameter is null, does not contain BOM information or does not contain an System.Xml.XmlDeclaration.
Returns
- Boolean
true
if thevalue
parameter was converted successfully; otherwise,false
.
Exceptions
- System.ArgumentNullException
value
cannot be null.