EncodingProvider Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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:
ASCII (code page 20127), which is returned by the Encoding.ASCII property.
ISO-8859-1 (code page 28591).
UTF-7 (code page 65000), which is returned by the Encoding.UTF7 property.
UTF-8 (code page 65001), which is returned by the Encoding.UTF8 property.
UTF-16 and UTF-16LE (code page 1200), which is returned by the Unicode property.
UTF-16BE (code page 1201), which is instantiated by calling the UnicodeEncoding.UnicodeEncoding(Boolean, Boolean) or UnicodeEncoding.UnicodeEncoding(Boolean, Boolean) constructor with a
bigEndian
value oftrue
.UTF-32 and UTF-32LE (code page 12000), which is returned by the Encoding.UTF32 property.
UTF-32BE (code page 12001), which is instantiated by calling an UTF32Encoding constructor that has a
bigEndian
parameter and providing a value oftrue
in the method call.
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:
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.
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.
Pass the EncodingProvider instance to the Encoding.RegisterProvider method to make the encodings supplied by the EncodingProvider object available to the common language runtime.
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) |
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() |
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) |