DecoderFallback 类
定义
为不能转换为输出字符的已编码输入字节序列提供称为“回退”的失败处理机制。Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that cannot be converted to an output character.
public ref class DecoderFallback abstract
public abstract class DecoderFallback
[System.Serializable]
public abstract class DecoderFallback
type DecoderFallback = class
[<System.Serializable>]
type DecoderFallback = class
Public MustInherit Class DecoderFallback
- 继承
-
DecoderFallback
- 派生
- 属性
注解
编码将 Unicode 字符映射到编码的字节序列。An encoding maps a Unicode character to an encoded sequence of bytes. 特定的编码由派生自类的类型表示 Encoding 。A particular encoding is represented by a type that is derived from the Encoding class. 具体而言,通过调用编码类型的方法将字符编码为字节序列 Encoding.GetBytes ,并通过调用或方法将字节序列解码为字符数组或字符串 Encoding.GetChars Encoding.GetString 。Specifically, a character is encoded to a byte sequence by calling the encoding type's Encoding.GetBytes method, and the byte sequence is decoded to a character array or a string by calling the Encoding.GetChars or Encoding.GetString method.
如果编码不能映射输入字节序列,解码操作可能会失败。A decoding operation can fail if the input byte sequence cannot be mapped by the encoding. 例如,如果某个 ASCIIEncoding 字节序列表示其码位值超出了 u + 0000 到 u + 007F 的字符,则对象无法对该序列序列进行解码。For example, an ASCIIEncoding object cannot decode a byte sequence if that sequence represents a character that has a code point value that is outside the range U+0000 to U+007F.
当无法执行解码转换时,.NET Framework 提供称为 "回退" 的失败处理机制。When a decoding conversion cannot be performed, the .NET Framework provides a failure-handling mechanism called a fallback. 应用程序可以使用预定义的 .NET Framework 解码器回退,也可以创建派生自和类的自定义解码器回退 DecoderFallback DecoderFallbackBuffer 。Your application can use predefined .NET Framework decoder fallbacks, or it can create a custom decoder fallback derived from the DecoderFallback and DecoderFallbackBuffer classes.
DecoderFallback 和 DecoderFallbackBuffer 是 .NET Framework 中所有解码回退处理程序的基类。DecoderFallback and DecoderFallbackBuffer are the base classes for all decoding fallback handlers in the .NET Framework. 它们支持以下三种类型的回退处理机制:They support the following three kinds of fallback handling mechanisms:
最佳回退,可映射无法解码为近似等效项的有效 Unicode 字符。Best-fit fallback, which maps valid Unicode characters that cannot be decoded to an approximate equivalent. 例如,类的最佳回退处理程序 ASCIIEncoding 可能会将Æ (u + 00C6) 映射到 AE (u + 0041 + u + 0045) 。For example, a best-fit fallback handler for the ASCIIEncoding class might map Æ (U+00C6) to AE (U+0041 + U+0045). 还可以实现最佳回退处理程序,以将 ((如西里尔) )的一种字母表为其他 (如拉丁语或罗马字) 。A best-fit fallback handler might also be implemented to transliterate one alphabet (such as Cyrillic) to another (such as Latin or Roman). .NET Framework 不提供任何公共最佳回退实现。The .NET Framework does not provide any public best-fit fallback implementations.
替换回退:替换无法使用预定义字符串解码的每个字符。Replacement fallback, which replaces each character that cannot be decoded with a predefined string. .NET Framework 提供预定义的替换回退处理程序。The .NET Framework provides a predefined replacement fallback handler. DecoderReplacementFallback类将不能解码的每个字节序列替换为问号字符 ( "?" 或 u + 003F) 或替换字符 (u + FFFD) 。The DecoderReplacementFallback class replaces each byte sequence that cannot be decoded with a question mark character ("?", or U+003F) or a REPLACEMENT CHARACTER (U+FFFD). 您可以通过在对构造函数的调用中指定替换来自定义替换字符串 DecoderReplacementFallback.DecoderReplacementFallback(String) 。You can customize the replacement string by specifying a substitute in the call to the DecoderReplacementFallback.DecoderReplacementFallback(String) constructor. 发出替换字符串后,解码操作将继续转换输入的其余部分。After the substitute string is emitted, the decoding operation continues converting the remainder of the input.
异常回退,当无法对字节序列进行解码时,将引发异常。Exception fallback, which throws an exception when a byte sequence cannot be decoded. .NET Framework 提供预定义的异常回退处理程序。The .NET Framework provides a predefined exception fallback handler. DecoderExceptionFallback DecoderFallbackException 当遇到无效的字节序列时,类将引发,而解码操作将终止。The DecoderExceptionFallback class throws a DecoderFallbackException when an invalid byte sequence is encountered, and the decoding operation terminates.
如果选择实现自定义解决方案,则必须重写类的以下抽象成员 DecoderFallback :If you choose to implement a custom solution, you must override the following abstract members of the DecoderFallback class:
CreateFallbackBuffer方法,它返回派生自的类实例 DecoderFallbackBuffer 。The CreateFallbackBuffer method, which returns a class instance derived from DecoderFallbackBuffer. 根据要开发的回退处理程序的类型, DecoderFallbackBuffer 实现负责执行映射或替换,或引发异常。Depending on the type of fallback handler that you are developing, the DecoderFallbackBuffer implementation is responsible for performing the mapping or replacement, or for throwing the exception.
MaxCharCount属性,该属性返回回退实现可返回的最大字符数。The MaxCharCount property, which returns the maximum number of characters that the fallback implementation can return. 对于异常回退处理程序,其值应为零。For an exception fallback handler, its value should be zero.
有关编码、解码和回退策略的详细信息,请参阅 .NET Framework 中的字符编码。For more information about encoding, decoding, and fallback strategies, see Character Encoding in the .NET Framework.
构造函数
| DecoderFallback() |
初始化 DecoderFallback 类的新实例。Initializes a new instance of the DecoderFallback class. |
属性
| ExceptionFallback |
获取无法解码输入字节序列时引发异常的对象。Gets an object that throws an exception when an input byte sequence cannot be decoded. |
| MaxCharCount |
当用派生类重写时,获取当前 DecoderFallback 对象能返回的最大字符数。When overridden in a derived class, gets the maximum number of characters the current DecoderFallback object can return. |
| ReplacementFallback |
获取输出替代字符串的对象,以替代无法解码的输入字节序列。Gets an object that outputs a substitute string in place of an input byte sequence that cannot be decoded. |
方法
| CreateFallbackBuffer() |
在派生类中重写时,将初始化 DecoderFallbackBuffer 类的新实例。When overridden in a derived class, initializes a new instance of the DecoderFallbackBuffer class. |
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |