EncodingProvider::GetEncoding Method (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.
Assembly: mscorlib (in mscorlib.dll)
public: virtual Encoding^ GetEncoding( String^ name, EncoderFallback^ encoderFallback, DecoderFallback^ decoderFallback )
Parameters
- name
-
Type:
System::String^
The name of the preferred 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 the current encoding.
Return Value
Type: System.Text::Encoding^The encoding that is associated with the specified name, or null if this EncodingProvider cannot return a valid encoding that corresponds to name.
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:
Exception fallback. If the encoderFallback argument is an instance of EncoderExceptionFallback, or the decoderExceptionFallback argument is an instance of DecoderExceptionFallback, the encoding method throws an exception if characters cannot be encoded, and the decoding method throws an exception if a byte sequence cannot be decoded.
Replacement fallback. If the encoderFallback argument is an instance of EncoderReplacementFallback, or the decoderExceptionFallback argument is an instance of DecoderReplacementFallback, the encoding and decoding methods substitute a replacement string for characters that cannot be encoded and byte sequences cannot be decoded. If you instantiated the replacement fallback object by calling the default constructor, the replacement character is a "?". If you call the EncoderReplacementFallback::EncoderReplacementFallback(String^) or DecoderReplacementFallback::DecoderReplacementFallback(String^) constructor, you can specify the replacement string.
Best-fit fallback. You can derive from the EncoderFallback or DecoderFallback class to implement a best-fit replacement mechanism.
Notes to Callers:
This method is called by the Encoding::GetEncoding(String^, 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(String^) method, you do not have to override it. When user code attempts to retrieve an encoding by calling the GetEncoding(String^, 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.
Available since 10
.NET Framework
Available since 4.6