Upraviť

Zdieľať cez


EncodingProvider Class

Definition

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
Inheritance
EncodingProvider
Derived
Attributes

Remarks

An encoding provider supplies encodings that are not otherwise available on a particular target platform.

The .NET Framework supports a large number of character encodings and code pages. You can get a complete list of encodings available in the .NET Framework by calling the Encoding.GetEncodings method. .NET Core, on the other hand, by default supports only the following encodings:

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. 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. Note that you can also choose to return a default encoding if the GetEncoding(Int32) method is called with an argument of 0.

  2. 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. 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. Call an Encoding.GetEncoding overload to retrieve the encoding. The Encoding.GetEncoding method will call the corresponding EncodingProvider.GetEncoding to determine whether it can supply the requested encoding.

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 applications. In addition, you can derive from the EncodingProvider class to make your own encodings available.

Constructors

EncodingProvider()

Initializes a new instance of the EncodingProvider class.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
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(Int32)

Returns the encoding associated with the specified code page identifier.

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.

GetEncoding(String)

Returns the encoding with the specified name.

GetEncodings()

Returns an array that contains all the encodings that are supported by the EncodingProvider.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also