Bewerken

Delen via


Encoding.RegisterProvider(EncodingProvider) Method

Definition

Registers an encoding provider.

public:
 static void RegisterProvider(System::Text::EncodingProvider ^ provider);
[System.Security.SecurityCritical]
public static void RegisterProvider (System.Text.EncodingProvider provider);
public static void RegisterProvider (System.Text.EncodingProvider provider);
[<System.Security.SecurityCritical>]
static member RegisterProvider : System.Text.EncodingProvider -> unit
static member RegisterProvider : System.Text.EncodingProvider -> unit
Public Shared Sub RegisterProvider (provider As EncodingProvider)

Parameters

provider
EncodingProvider

A subclass of EncodingProvider that provides access to additional character encodings.

Attributes

Exceptions

provider is null.

Remarks

The RegisterProvider method allows you to register a class derived from EncodingProvider that makes character encodings available on a platform that does not otherwise support them. Once the encoding provider is registered, the encodings that it supports can be retrieved by calling any Encoding.GetEncoding overload. If there are multiple encoding providers, the Encoding.GetEncoding method attempts to retrieve a specified encoding from each provider starting with the one most recently registered.

Registering an encoding provider by using the RegisterProvider method also modifies the behavior of the Encoding.GetEncoding(Int32) and EncodingProvider.GetEncoding(Int32, EncoderFallback, DecoderFallback) methods when passed an argument of 0:

  • If the registered provider is the CodePagesEncodingProvider, the method returns the encoding that matches the system active code page when running on the Windows operating system.

  • A custom encoding provider can choose which encoding to return when either of these GetEncoding method overloads is passed an argument of 0. The provider can also choose to not return an encoding by having the EncodingProvider.GetEncoding method return null.

Starting with .NET Framework 4.6, .NET Framework includes one encoding provider, CodePagesEncodingProvider, that makes the encodings available that are present in the full .NET Framework but are not available in the Universal Windows Platform. By default, the Universal Windows Platform only supports the Unicode encodings, ASCII, and code page 28591.

If the same encoding provider is used in multiple calls to the RegisterProvider method, only the first method call registers the provider. Subsequent calls are ignored.

If the RegisterProvider method is called to register multiple providers that handle the same encoding, the last registered provider is the used for all encoding and decoding operations. Any previously registered providers are ignored.

Applies to

See also