DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="1.2.2" />

 DecodingContext

public struct DecodingContext
Represents text decoding context.
using System; using System.Runtime.InteropServices; using System.Text; namespace DotNext.Text { [StructLayout(LayoutKind.Auto)] public readonly struct DecodingContext { private readonly Encoding encoding; private readonly Decoder decoder; public Encoding Encoding => encoding ?? Encoding.Default; public DecodingContext(Encoding encoding, bool reuseDecoder = false) { if (encoding == null) throw new ArgumentNullException("encoding"); this.encoding = encoding; decoder = (reuseDecoder ? encoding.GetDecoder() : null); } public void Reset() { decoder?.Reset(); } internal Decoder GetDecoder() { return decoder ?? Encoding.GetDecoder(); } public static implicit operator DecodingContext(Encoding encoding) { return new DecodingContext(encoding, false); } } }