Skip to content

Commit

Permalink
Fix the Xamarin encoding exception #1460
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed May 11, 2020
1 parent 071bf9c commit 28d40a3
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/RestSharp/Extensions/StringEncodingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ namespace RestSharp.Extensions
{
public static class StringEncodingExtensions
{
static readonly Dictionary<string, Encoding> Encodings = new Dictionary<string, Encoding>();

static StringEncodingExtensions()
{
var encodings = Encoding.GetEncodings();

foreach (var encoding in encodings)
{
Encodings[encoding.Name] = encoding.GetEncoding();
}
}

/// <summary>
/// Converts a byte array to a string, using its byte order mark to convert it to the right encoding.
/// http://www.shrinkrays.net/code-snippets/csharp/an-extension-method-for-converting-a-byte-array-to-a-string.aspx
Expand All @@ -43,7 +31,7 @@ static StringEncodingExtensions()
[Obsolete("This method will be removed soon. If you use it, please copy the code to your project.")]
public static string AsString(this byte[] buffer, string? encoding)
{
var enc = encoding.IsEmpty() ? Encoding.UTF8 : Encodings.TryGetValue(encoding!, out var e) ? e : Encoding.UTF8;
var enc = encoding.IsEmpty() ? Encoding.UTF8 : Encoding.GetEncoding(encoding) ?? Encoding.UTF8;

return AsString(buffer, enc);
}
Expand Down

0 comments on commit 28d40a3

Please sign in to comment.