Class ByteOrderMark
Provides a set of static methods for Unicode related operations.
public static class ByteOrderMark
- Inheritance
-
ByteOrderMark
Methods
Decode(byte[])
Decodes a BOM-preamble of the specified bytes to its equivalent Encoding representation.
public static Encoding Decode(byte[] bytes)
Parameters
Returns
Exceptions
- ArgumentNullException
bytescannot be null.- ArgumentException
byteswas without byte order mark information (BOM).
DetectEncodingOrDefault(byte[], Encoding)
Tries to detect an Encoding object from the specified input.
If unsuccessful, the fallbackEncoding value is returned. Default is DefaultEncoding.
public static Encoding DetectEncodingOrDefault(byte[] input, Encoding fallbackEncoding)
Parameters
inputbyte[]The byte[] to parse for an Encoding.
fallbackEncodingEncodingThe Encoding to use when conversion is unsuccessful.
Returns
- Encoding
Either the detected encoding of
inputor thefallbackEncodingencoding.
DetectEncodingOrDefault(Stream, Encoding)
Tries to detect an Encoding object from the specified value.
If unsuccessful, the fallbackEncoding value is returned.
public static Encoding DetectEncodingOrDefault(Stream value, Encoding fallbackEncoding)
Parameters
Returns
- Encoding
Either the detected encoding of
valueor thefallbackEncodingencoding.
Remove(byte[], Encoding)
Removes the preamble information (if present) from the specified byte[].
public static byte[] Remove(byte[] bytes, Encoding encoding)
Parameters
bytesbyte[]The bytes byte[] to process.
encodingEncodingThe encoding to use when determining the preamble to remove.
Returns
Remove(Stream, Encoding, Action<DisposableOptions>)
Removes the preamble information (if present) from the specified Stream.
public static Stream Remove(Stream value, Encoding encoding, Action<DisposableOptions> setup = null)
Parameters
valueStreamThe Stream to process.
encodingEncodingThe encoding to use when determining the preamble to remove.
setupAction<DisposableOptions>The DisposableOptions which may be configured.
Returns
TryDetectEncoding(byte[], out Encoding)
Tries to resolve the Unicode Encoding object from the specified byte[].
public static bool TryDetectEncoding(byte[] input, out Encoding result)
Parameters
inputbyte[]The byte[] to resolve the Unicode Encoding object from.
resultEncodingWhen this method returns, it contains the Unicode Encoding value equivalent to the encoding contained in
input, if the conversion succeeded, or a null reference (Nothing in Visual Basic) if the conversion failed. The conversion fails if theinputparameter is null, or does not contain a Unicode representation of an Encoding.
Returns
- bool
trueif theinputparameter was converted successfully; otherwise,false.
TryDetectEncoding(Stream, out Encoding)
public static bool TryDetectEncoding(Stream value, out Encoding result)
Parameters
valueStreamThe Stream object to resolve the Unicode Encoding object from.
resultEncodingWhen this method returns, it contains the Unicode Encoding value equivalent to the encoding contained in
value, if the conversion succeeded, or a null reference (Nothing in Visual Basic) if the conversion failed. The conversion fails if thevalueparameter is null, or does not contain a Unicode representation of an Encoding.
Returns
- bool
trueif thevalueparameter was converted successfully; otherwise,false.