System.Text.EncoderReplacementFallback Class

Provides a failure handling mechanism, called a fallback, for an input character that cannot be converted to an output byte sequence. The fallback uses a user-specified replacement string instead of the original input character. This class cannot be inherited.

See Also: EncoderReplacementFallback Members

Syntax

public sealed class EncoderReplacementFallback : EncoderFallback

Remarks

A common reason for an encoding or decoding operation to fail is if the underlying encoding class does not provide a mapping between a character and an equivalent byte sequence. For example, an System.Text.ASCIIEncoding object cannot encode a character having a Unicode code point value that is outside the range U+0000 to U+007F. If the input character cannot be converted to an output byte sequence, a System.Text.EncoderReplacementFallback object substitutes a specified replacement string for the original input character. The conversion process encodes the replacement string and then continues to process the remainder of the original input.

The value of a System.Text.EncoderReplacementFallback object is the replacement string used to initialize that object.

This class is one of two .NET Framework classes that implement different fallback strategies for handling encoding conversion failures. The other class is the System.Text.EncoderExceptionFallback class, which throws an System.Text.EncoderFallbackException when an invalid character is encountered.

When you choose a fallback string to use with this class, make sure that the string is composed entirely of characters that can be encoded in the target encoding. Otherwise, a recursive fallback results, causing an ArgumentException.

Requirements

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0