diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs index bbf5d62abea0bb..20496b54c5c2e1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs @@ -1019,6 +1019,11 @@ public virtual string GetString(byte[] bytes, int index, int count) => public static Encoding UTF8 => UTF8Encoding.s_default; + // Returns an encoding for the UTF-8 format without BOM. The returned encoding will be + // an instance of the UTF8Encoding class. + + public static Encoding UTF8NoBOM => UTF8Encoding.s_noBom; + // Returns an encoding for the UTF-32 format. The returned encoding will be // an instance of the UTF32Encoding class. diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs index a8b3626c908702..495a56d88d7cf2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs @@ -61,6 +61,10 @@ 4 21 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv // The initialization code will not be run until a static member of the class is referenced internal static readonly UTF8EncodingSealed s_default = new UTF8EncodingSealed(encoderShouldEmitUTF8Identifier: true); + // Used by Encoding.UTF8NoBOM for lazy initialization + // The initialization code will not be run until a static member of the class is referenced + internal static readonly UTF8EncodingSealed s_noBom = new UTF8EncodingSealed(encoderShouldEmitUTF8Identifier: false); + internal static ReadOnlySpan PreambleSpan => new byte[3] { 0xEF, 0xBB, 0xBF }; // uses C# compiler's optimization for static byte[] data // Yes, the idea of emitting U+FEFF as a UTF-8 identifier has made it into