EncodingProvider::GetEncoding Method (Int32, EncoderFallback^, DecoderFallback^)

.NET Framework (current version)
 

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.

Namespace:   System.Text
Assembly:  mscorlib (in mscorlib.dll)

public:
virtual Encoding^ GetEncoding(
	int codepage,
	EncoderFallback^ encoderFallback,
	DecoderFallback^ decoderFallback
)

Parameters

codepage
Type: System::Int32

The code page identifier of the requested encoding.

encoderFallback
Type: System.Text::EncoderFallback^

An object that provides an error-handling procedure when a character cannot be encoded with this encoding.

decoderFallback
Type: System.Text::DecoderFallback^

An object that provides an error-handling procedure when a byte sequence cannot be decoded with this encoding.

Return Value

Type: System.Text::Encoding^

The encoding that is associated with the specified code page, or null if this EncodingProvider cannot return a valid encoding that corresponds to codepage.

The encoderFallback and decoderFallback parameters are objects that define the fallback strategy used in the event that an encoder cannot convert a character to a sequence of bytes or a decoder cannot convert a sequence of bytes to a character. The .NET Framework provides the following fallback mechanisms:

Notes to Callers:

This method is called by the Encoding::GetEncoding(Int32, EncoderFallback^, DecoderFallback^) method. You should not call it directly from user code.

Notes to Inheritors:

Because calls to this method use your implementation of the GetEncoding(Int32) method, you do not have to override it. When user code attempts to retrieve an encoding by calling the Encoding::GetEncoding(Int32, EncoderFallback^, DecoderFallback^) method, the method passes the codepage identifier to every registered encoding provider until one returns a valid encoding. If none returns a valid encoding, the Encoding::GetEncoding method attempts to retrieve a cached encoding whose code page identifier is codepage. Because of this, if you do choose to override the GetEncoding(Int32, EncoderFallback^, DecoderFallback^) method, your override should return null if codepage is not the code page identifier of an encoding that you support; it should never throw an exception.

Universal Windows Platform
Available since 10
.NET Framework
Available since 4.6
Return to top
Show: