EncodingProvider 类

定义

提供编码提供程序的基类,后者提供在特定平台上不可用的编码。Provides the base class for an encoding provider, which supplies encodings that are unavailable on a particular platform.

public ref class EncodingProvider abstract
public abstract class EncodingProvider
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class EncodingProvider
type EncodingProvider = class
Public MustInherit Class EncodingProvider
继承
EncodingProvider
派生
属性

注解

编码提供程序提供特定目标平台上不可用的其他编码。An encoding provider supplies encodings that are not otherwise available on a particular target platform.

Windows 桌面上的 .NET Framework 支持大量字符编码和代码页。The .NET Framework on the Windows desktop supports a large number of character encodings and code pages. 可以通过调用 Encoding.GetEncodings 方法获取 Windows 桌面上 .NET Framework 的完整编码列表。You can get a complete list of encodings available in the .NET Framework on the Windows desktop by calling the Encoding.GetEncodings method. 另一方面,.NET Core 默认仅支持以下编码:.NET Core, on the other hand, by default supports only the following encodings:

从 .NET Framework 4.6 开始,EncodingProvider 是使 .NET Framework 可用的其他不可用编码的基类。Starting with the .NET Framework 4.6, EncodingProvider is the base class that makes otherwise unavailable encodings available to the .NET Framework. 这包括以下步骤:This involves the following steps:

  1. 定义 EncodingProvider 的子类,该子类重写两个抽象 GetEncoding 重载,GetEncoding(Int32)GetEncoding(String)Define a subclass of EncodingProvider that overrides the two abstract GetEncoding overloads, GetEncoding(Int32) and GetEncoding(String). 这些重载按代码页标识符和名称返回其他不受支持的编码。These overloads return the otherwise unsupported encoding by code page identifier and by name. 请注意,如果使用参数0调用 GetEncoding(Int32) 方法,还可以选择返回默认编码。Note that you can also choose to return a default encoding if the GetEncoding(Int32) method is called with an argument of 0.

  2. 还可以选择重写虚拟 GetEncoding(Int32, EncoderFallback, DecoderFallback)GetEncoding(String, EncoderFallback, DecoderFallback) 方法。Optionally, you can override the virtual GetEncoding(Int32, EncoderFallback, DecoderFallback) and GetEncoding(String, EncoderFallback, DecoderFallback) methods. 在大多数情况下,这并不是必需的,因为基类提供了默认实现。In most cases, this is not necessary, since the base class provides a default implementation.

  3. EncodingProvider 实例传递到 Encoding.RegisterProvider 方法,以使 EncodingProvider 对象提供的编码可供公共语言运行时使用。Pass the EncodingProvider instance to the Encoding.RegisterProvider method to make the encodings supplied by the EncodingProvider object available to the common language runtime.

  4. 调用 Encoding.GetEncoding 重载以检索编码。Call an Encoding.GetEncoding overload to retrieve the encoding. Encoding.GetEncoding 方法将调用相应的 EncodingProvider.GetEncoding 来确定它是否可以提供请求的编码。The Encoding.GetEncoding method will call the corresponding EncodingProvider.GetEncoding to determine whether it can supply the requested encoding.

.NET Framework 类库提供一个静态属性,CodePagesEncodingProvider.Instance,该属性返回一个 EncodingProvider 对象,该对象可在桌面 .NET Framework 类库可用以 .NET Core.NET Core 应用程序。The .NET Framework Class Library provides one static property, CodePagesEncodingProvider.Instance, that returns an EncodingProvider object that makes the full set of encodings available on the desktop .NET Framework Class Library available to .NET Core.NET Core applications. 此外,还可以从 EncodingProvider 类派生,使自己的编码可用。In addition, you can derive from the EncodingProvider class to make your own encodings available.

构造函数

EncodingProvider()

初始化 EncodingProvider 类的新实例。Initializes a new instance of the EncodingProvider class.

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEncoding(Int32)

返回与指定代码页标识符关联的编码。Returns the encoding associated with the specified code page identifier.

GetEncoding(Int32, EncoderFallback, DecoderFallback)

返回与指定代码页标识符关联的编码。Returns the encoding associated with the specified code page identifier. 参数指定一个错误处理程序,用于处理无法编码的字符和无法解码的字节序列。Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded.

GetEncoding(String)

返回具有指定名称的编码。Returns the encoding with the specified name.

GetEncoding(String, EncoderFallback, DecoderFallback)

返回与指定名称关联的编码。Returns the encoding associated with the specified name. 参数指定一个错误处理程序,用于处理无法编码的字符和无法解码的字节序列。Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets 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)

适用于

另请参阅