DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.2.0-beta.1" />

 EncodingWithoutPreamble

using System; using System.Diagnostics.CodeAnalysis; using System.Text; namespace DotNext.Text { internal sealed class EncodingWithoutPreamble : Encoding { private readonly Encoding encoding; public override ReadOnlySpan<byte> Preamble => default(ReadOnlySpan<byte>); public override string BodyName => encoding.BodyName; public override int CodePage => encoding.CodePage; public override string EncodingName => encoding.EncodingName; public override string HeaderName => encoding.HeaderName; public override int WindowsCodePage => encoding.WindowsCodePage; public override string WebName => encoding.WebName; public override bool IsSingleByte => encoding.IsSingleByte; public override bool IsBrowserDisplay => encoding.IsBrowserDisplay; public override bool IsBrowserSave => encoding.IsBrowserSave; public override bool IsMailNewsDisplay => encoding.IsMailNewsDisplay; public override bool IsMailNewsSave => encoding.IsMailNewsSave; private EncodingWithoutPreamble(Encoding enc) : base(enc.WindowsCodePage, enc.EncoderFallback, enc.DecoderFallback) { encoding = enc; } internal static Encoding Create(Encoding enc) { return new EncodingWithoutPreamble(enc); } public override byte[] GetPreamble() { return Array.Empty<byte>(); } public override int GetByteCount(char[] chars, int index, int count) { return encoding.GetByteCount(chars, index, count); } public override int GetByteCount(ReadOnlySpan<char> chars) { return encoding.GetByteCount(chars); } public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { return encoding.GetBytes(chars, charIndex, charCount, bytes, byteIndex); } public override int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes) { return encoding.GetBytes(chars, bytes); } public override int GetCharCount(byte[] bytes, int index, int count) { return encoding.GetCharCount(bytes, index, count); } public override int GetCharCount(ReadOnlySpan<byte> bytes) { return encoding.GetCharCount(bytes); } public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { return encoding.GetChars(bytes, byteIndex, byteCount, chars, charIndex); } public override int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars) { return encoding.GetChars(bytes, chars); } public override int GetMaxByteCount(int charCount) { return encoding.GetMaxByteCount(charCount); } public override int GetMaxCharCount(int byteCount) { return encoding.GetMaxCharCount(byteCount); } public unsafe override int GetByteCount(char* chars, int count) { return encoding.GetByteCount(chars, count); } public override int GetByteCount(char[] chars) { return encoding.GetByteCount(chars); } public override int GetByteCount(string s) { return encoding.GetByteCount(s); } public override byte[] GetBytes(char[] chars) { return encoding.GetBytes(chars); } public override object Clone() { return new EncodingWithoutPreamble(encoding); } public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { return encoding.GetBytes(chars, charCount, bytes, byteCount); } public override byte[] GetBytes(char[] chars, int index, int count) { return encoding.GetBytes(chars, index, count); } public override byte[] GetBytes(string s) { return encoding.GetBytes(s); } public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) { return encoding.GetBytes(s, charIndex, charCount, bytes, byteIndex); } public unsafe override int GetCharCount(byte* bytes, int count) { return encoding.GetCharCount(bytes, count); } public override int GetCharCount(byte[] bytes) { return encoding.GetCharCount(bytes); } public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { return encoding.GetChars(bytes, byteCount, chars, charCount); } public override char[] GetChars(byte[] bytes) { return encoding.GetChars(bytes); } public override bool IsAlwaysNormalized(NormalizationForm form) { return encoding.IsAlwaysNormalized(form); } public override char[] GetChars(byte[] bytes, int index, int count) { return encoding.GetChars(bytes, index, count); } public override Decoder GetDecoder() { return encoding.GetDecoder(); } public override Encoder GetEncoder() { return encoding.GetEncoder(); } public override string GetString(byte[] bytes) { return encoding.GetString(bytes); } public override string GetString(byte[] bytes, int index, int count) { return encoding.GetString(bytes, index, count); } public override string ToString() { return encoding.ToString(); } public override bool Equals([NotNullWhen(true)] object other) { EncodingWithoutPreamble encodingWithoutPreamble = other as EncodingWithoutPreamble; if (encodingWithoutPreamble == null) return encoding.Equals(other); return encoding.Equals(encodingWithoutPreamble.encoding); } public override int GetHashCode() { return encoding.GetHashCode(); } } }