-
Notifications
You must be signed in to change notification settings - Fork 44
Add custom charset support
0.13.0
ASE allows for a multitude of "charsets" (string encodings) to be used over-the-wire between the driver and the server.
Out of the box, .net core (and therefore the driver) does not support very many of these -- only the most common ones, such as:
ASCII
UTF-8
ISO-8859-1
For sure, there are legacy ASE systems which use different charsets to the above, so the driver has a facility to enable support...
You (the driver user) can add support for a charset by extending System.Text.EncodingProvider
and registering the extension via System.Text.Encoding.RegisterProvider(...)
.
When the server informs the driver that a particular charset should be used, the driver will attempt to load that encoding by name, using Encoding.GetEncoding(string name)
.
In addition, for many of the charsets ASE supports, you can leverage existing Encoding
implementations provided by the System.Text.CodePagesEncodingProvider
which is part of the System.Text.Encoding.CodePages
NuGet package.
Below is a more concrete example of how to accomplish this.
- Add the
System.Text.Encoding.CodePages
NuGet package - Extend
EncodingProvider
to map"cp850"
to anEncoding
public class MyEncodingProvider : EncodingProvider
{
public override Encoding GetEncoding(int codepage)
{
return null; // we're only matching on name, not codepage
}
public override Encoding GetEncoding(string name)
{
if(string.Equals("cp850", name, StringComparison.OrdinalIgnoreCase))
{
return Encoding.GetEncoding(850); // this will load an encoding from the CodePagesEncodingProvider
}
return null;
}
}
- Register
CodePagesEncodingProvider
andMyEncodingProvider
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding.RegisterProvider(new MyEncodingProvider());
- Start using the driver
- Using the driver
- Developing the driver