Export (0) Print
Expand All

DecoderFallback Class


Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that cannot be converted to an output character.

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

public abstract class DecoderFallback
/** @attribute SerializableAttribute() */ 
public abstract class DecoderFallback
public abstract class DecoderFallback

An encoding maps a Unicode character to an encoded sequence of bytes, which can subsequently be transferred to a physical medium, such as a disk, or over a communications link. Characters can be mapped in various ways, and a particular encoding is represented by a type derived from the Encoding class. Specifically, the encoding type's GetBytes method encodes a character to a byte sequence, and the GetChars method decodes a byte sequence to a character.

However, a decoding operation can fail if the input byte sequence cannot be mapped by the encoding. For example, an ASCIIEncoding object cannot decode a byte sequence that yields a character whose code point value is outside the range U+0000 to U+007F.

In cases where an encoding or decoding conversion cannot be performed, the .NET Framework provides a failure-handling mechanism called a fallback. Your code can use predefined .NET Framework encoder and decoder fallbacks, or you can create a custom encoder fallback derived from the EncoderFallback and EncoderFallbackBuffer classes or a custom decoder fallback derived from the DecoderFallback and DecoderFallbackBuffer classes.

The .NET Framework provides two predefined classes that implement different fallback strategies for handling decoding conversion failures. The DecoderReplacementFallback class substitutes a string that you provide in place of any input byte sequence that cannot be converted. After the substitute string is emitted, the decoding operation continues converting the remainder of the input. In contrast, the DecoderExceptionFallback class throws a DecoderFallbackException when an invalid byte sequence is encountered.




.NET Framework

Supported in: 2.0

Community Additions

© 2015 Microsoft