Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine the default encoding in a portable class library?

With .NET 4.6 I can detect the current codepage with:

System.Text.Encoding.Default

Now I'm trying to port a class library that is reading files from a standard class library to a portable class library, supporting ASP.NET Core 5. With this configuration, Encoding.Default is not availiable.

Of course, any recent file should be saved in UTF-8 encoding, but I can not ensure that all files are stored in this encoding.

Is there another way to get the default codepage?

I looked at the reference source and found that Encoding.Default is implemented (more ore less) with an Win32 Api call...

like image 850
ventiseis Avatar asked Mar 10 '16 23:03

ventiseis


People also ask

What is portable class library?

The Portable Class Library project enables you to write and build managed assemblies that work on more than one . NET Framework platform. You can create classes that contain code you wish to share across many projects, such as shared business logic, and then reference those classes from different types of projects.

What is .NET PCL?

Portable Class Libraries (PCL)


1 Answers

According to the documentation here: Encoding.GetEncoding Method (Int32), you can use Encoding.GetEncoding(0) to get the default encoding.

like image 198
Matt H Avatar answered Oct 28 '22 13:10

Matt H