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
[<System.Runtime.InteropServices.ComVisible(true)>]
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. 您可以藉由呼叫方法,取得 Windows 桌面上 .NET Framework 中可用的完整編碼清單 Encoding.GetEncodingsYou 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 它會覆寫兩個抽象多載 GetEncodingGetEncoding(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. 請注意,如果 GetEncoding(Int32) 呼叫的方法具有0的引數,您也可以選擇傳回預設編碼。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 給 common language runtime。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.

GetEncodings()

傳回陣列,其中包含 EncodingProvider 支援的所有編碼。Returns an array that contains all the encodings that are supported by the EncodingProvider.

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)

適用於

另請參閱