18 types derived from Encoding
dotnet-svcutil-lib (3)
Roslyn.VisualStudio.Next.UnitTests (1)
System.Console (1)
System.Formats.Asn1 (2)
System.Private.CoreLib (7)
System.Private.DataContractSerialization (2)
System.Private.Xml (1)
System.Text.Encoding.CodePages (1)
6093 references to Encoding
AnalyzerRunner (2)
aspire (1)
Aspire.Azure.Messaging.EventHubs.Tests (2)
Aspire.Azure.Security.KeyVault.Tests (2)
Aspire.Cli.Tests (2)
Aspire.Confluent.Kafka (2)
Aspire.Confluent.Kafka.Tests (3)
Aspire.Dashboard (8)
Aspire.Dashboard.Components.Tests (10)
Aspire.Dashboard.Tests (16)
Aspire.Hosting (10)
Aspire.Hosting.Azure (2)
Aspire.Hosting.Azure.Tests (2)
Aspire.Hosting.Kubernetes (2)
Aspire.Hosting.PostgreSQL (1)
Aspire.Hosting.RabbitMQ.Tests (4)
Aspire.Hosting.Seq.Tests (1)
Aspire.Hosting.Tests (11)
Aspire.RabbitMQ.Client.Tests (1)
Aspire.RabbitMQ.Client.v7.Tests (1)
AzureFunctionsEndToEnd.ApiService (2)
BasicWebSite (8)
Benchmarks (2)
BinaryFormatTests (1)
Binding.Http.IntegrationTests (1)
BoundTreeGenerator (1)
BuildBoss (3)
BuildValidator (1)
Client.TypedClient.IntegrationTests (3)
ClientSample (2)
CodeGenerator (13)
ConfigurationSchemaGenerator.Tests (1)
Contract.Service.IntegrationTests (2)
CorsMiddlewareWebSite (1)
csc (9)
CSharpErrorFactsGenerator (1)
CSharpSyntaxGenerator (4)
CustomAuthorizationFailureResponse (1)
dotnet-dev-certs (5)
dotnet-getdocument (1)
dotnet-razorpagegenerator (1)
dotnet-svcutil.xmlserializer (1)
dotnet-svcutil-lib (218)
FrameworkFork\Microsoft.Xml\Xml\Core\XmlTextReaderImpl.cs (31)
225private Encoding _reportedEncoding;
515Encoding enc = (context != null) ? context.Encoding : null;
544InitStringInput(string.Empty, Encoding.Unicode, xmlFragment);
549InitStringInput(context.BaseURI, Encoding.Unicode, xmlFragment);
563InitStringInput((context == null) ? string.Empty : context.BaseURI, Encoding.Unicode, string.Concat("<?xml ", xmlFragment, "?>"));
670Encoding enc = null;
745Encoding enc = null;
823InitStringInput(string.Empty, Encoding.Unicode, xmlFragment);
2091internal Encoding Encoding
2693InitStringInput(baseUri, Encoding.Unicode, internalDtd);
2874private void InitStreamInput(Stream stream, Encoding encoding)
2879private void InitStreamInput(string baseUriStr, Stream stream, Encoding encoding)
2885private void InitStreamInput(Uri baseUri, Stream stream, Encoding encoding)
2891private void InitStreamInput(Uri baseUri, string baseUriStr, Stream stream, Encoding encoding)
2896private void InitStreamInput(Uri baseUri, string baseUriStr, Stream stream, byte[] bytes, int byteCount, Encoding encoding)
3012_ps.encoding = Encoding.Unicode;
3020private void InitStringInput(string baseUriStr, Encoding originalEncoding, string str)
3164private Encoding DetectEncoding()
3198return Encoding.BigEndianUnicode;
3207return Encoding.Unicode;
3216return Encoding.Unicode;
3225return Encoding.BigEndianUnicode;
3247private void SetupEncoding(Encoding encoding)
3252_ps.encoding = Encoding.UTF8;
3275private void SwitchEncoding(Encoding newEncoding)
3289private Encoding CheckEncoding(string newEncodingName)
3318Encoding newEncoding = null;
3327newEncoding = Encoding.GetEncoding(newEncodingName);
3665Encoding encoding = null;
8158Encoding enc = _ps.encoding;
8175Encoding enc = _ps.encoding;
FrameworkFork\System.Runtime.Serialization\System\Xml\EncodingStreamWrapper.cs (9)
40private Encoding _encoding;
54public EncodingStreamWrapper(Stream stream, Encoding encoding)
122private static Encoding GetEncoding(SupportedEncoding e)
140private static Encoding GetSafeEncoding(SupportedEncoding e)
176private static SupportedEncoding GetSupportedEncoding(Encoding encoding)
191public EncodingStreamWrapper(Stream stream, Encoding encoding, bool emitBOM)
470internal static ArraySegment<byte> ProcessBuffer(byte[] buffer, int offset, int count, Encoding encoding)
491Encoding localEnc;
640_byteCount = Encoding.UTF8.GetBytes(_chars, 0, charCount, _bytes, 0);
FrameworkFork\System.Runtime.Serialization\System\Xml\XmlNodeWriter.cs (8)
35WriteStartElement(Encoding.UTF8.GetString(prefixBuffer, prefixOffset, prefixLength), Encoding.UTF8.GetString(localNameBuffer, localNameOffset, localNameLength));
50WriteEndElement(Encoding.UTF8.GetString(prefixBuffer, prefixOffset, prefixLength), Encoding.UTF8.GetString(localNameBuffer, localNameOffset, localNameLength));
55WriteXmlnsAttribute(Encoding.UTF8.GetString(prefixBuffer, prefixOffset, prefixLength), Encoding.UTF8.GetString(nsBuffer, nsOffset, nsLength));
61WriteStartAttribute(Encoding.UTF8.GetString(prefixBuffer, prefixOffset, prefixLength), Encoding.UTF8.GetString(localNameBuffer, localNameOffset, localNameLength));
FrameworkFork\System.Runtime.Serialization\System\Xml\XmlUTF8TextReader.cs (6)
26void SetInput(byte[] buffer, int offset, int count, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose);
27void SetInput(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose);
562public void SetInput(byte[] buffer, int offset, int count, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
580public void SetInput(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
666XmlExceptionHelper.ThrowTokenExpected(this, "?>", Encoding.UTF8.GetString(buffer, offset, 2));
1077XmlExceptionHelper.ThrowTokenExpected(this, "[CDATA[", Encoding.UTF8.GetString(buffer, offset, 7));
FrameworkFork\System.ServiceModel\Internals\System\Runtime\UrlUtility.cs (17)
14private static Encoding s_asciiEncoding;
16private static Encoding AsciiEncoding
22s_asciiEncoding = Encoding.GetEncoding("ascii");
31return ParseQueryString(query, Encoding.UTF8);
34public static NameValueCollection ParseQueryString(string query, Encoding encoding)
60return UrlEncode(str, Encoding.UTF8);
79return UrlEncodeSpaces(UrlEncodeNonAscii(str, Encoding.UTF8));
82public static string UrlEncode(string str, Encoding encoding)
140private static string UrlEncodeNonAscii(string str, Encoding e)
148e = Encoding.UTF8;
166public static byte[] UrlEncodeToBytes(string str, Encoding e)
176public static string UrlDecode(string str, Encoding e)
288private static string UrlDecodeStringFromStringInternal(string s, Encoding e)
416private Encoding _encoding;
427internal UrlDecoder(int bufferSize, Encoding encoding)
486internal HttpValueCollection(string str, Encoding encoding)
497internal void FillFromString(string s, bool urlencoded, Encoding encoding)
FrameworkFork\System.ServiceModel\System\ServiceModel\Channels\TextMessageEncoder.cs (18)
28public TextMessageEncoderFactory(MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas)
53public static Encoding[] GetSupportedEncodings()
55Encoding[] supported = TextEncoderDefaults.SupportedEncodings;
56Encoding[] enc = new Encoding[supported.Length];
92internal static string GetContentType(string mediaType, Encoding encoding)
99Encoding[] readEncodings = TextMessageEncoderFactory.GetSupportedEncodings();
112internal static Encoding GetEncodingFromContentType(string contentType, ContentEncoding[] contentMap)
184Encoding enc;
229internal static bool TryGetEncodingFromCharSet(string charSet, out Encoding encoding)
241internal Encoding encoding;
257private Encoding _writeEncoding;
265public TextMessageEncoder(MessageVersion version, Encoding writeEncoding, int maxReadPoolSize, int maxWritePoolSize, XmlDictionaryReaderQuotas quotas)
309private static bool IsUTF8Encoding(Encoding encoding)
355Encoding tmp;
615private XmlReader TakeStreamedReader(Stream stream, Encoding enc)
681private Encoding _encoding;
691internal Encoding Encoding
FrameworkFork\System.ServiceModel\System\ServiceModel\Channels\TransportDefaults.cs (18)
56public static readonly Encoding Encoding = Encoding.GetEncoding(TextEncoderDefaults.EncodingString);
58public static readonly Encoding[] SupportedEncodings = new Encoding[] { Encoding.UTF8, Encoding.Unicode, Encoding.BigEndianUnicode };
63new CharSetEncoding("utf-8", Encoding.UTF8),
64new CharSetEncoding("utf-16LE", Encoding.Unicode),
65new CharSetEncoding("utf-16BE", Encoding.BigEndianUnicode),
70public static void ValidateEncoding(Encoding encoding)
73Encoding[] supportedEncodings = SupportedEncodings;
82public static string EncodingToCharSet(Encoding encoding)
88Encoding enc = charSetEncodings[i].Encoding;
98public static bool TryGetEncoding(string charSet, out Encoding encoding)
133public Encoding Encoding;
135public CharSetEncoding(string charSet, Encoding enc)
338public static Encoding TextEncoding
dotnet-user-secrets (2)
Encoding.MessageVersion.IntegrationTests (7)
MessageVersionTests.cs (5)
30binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressingAugust2004, Encoding.UTF8), new HttpTransportBindingElement());
66binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap11WSAddressingAugust2004, Encoding.UTF8), new HttpTransportBindingElement());
102binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None), Encoding.UTF8), new HttpTransportBindingElement());
138binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.WSAddressing10), Encoding.UTF8), new HttpTransportBindingElement());
174binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.WSAddressing10), Encoding.UTF8), new TcpTransportBindingElement());
ExceptionHandlerSample (1)
Extensibility.MessageEncoder.IntegrationTests (3)
FilesWebSite (3)
FormatterWebSite (3)
GenerateDocumentationAndConfigFiles (1)
GetDocument.Insider (2)
http2cat (29)
src\Shared\runtime\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
HttpStress (2)
IdeCoreBenchmarks (1)
IIS.Common.TestLib (6)
TestConnections.cs (6)
66var bytes = Encoding.ASCII.GetBytes(string.Join("\r\n", lines));
112Assert.Equal(expected, Encoding.ASCII.GetString((await ReceiveChunk()).Span));
120Assert.Equal(expected, Encoding.ASCII.GetString(actual.Span));
151$"Actual:{Environment.NewLine}{Encoding.ASCII.GetString(actual, 0, offset)}{Environment.NewLine}",
186var actualLine = Encoding.ASCII.GetString(actual, 0, offset);
234$"Expected connection close, received data instead: \"{Encoding.ASCII.GetString(e.Buffer, 0, e.BytesTransferred)}\""));
IIS.FunctionalTests (40)
src\Shared\runtime\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
IIS.LongTests (28)
src\Shared\runtime\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
IIS.Microbenchmarks (1)
IIS.NewHandler.FunctionalTests (28)
src\Shared\runtime\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
IIS.NewShim.FunctionalTests (28)
src\Shared\runtime\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
IIS.ShadowCopy.Tests (6)
IISExpress.FunctionalTests (40)
src\Shared\runtime\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
illink (2)
Infrastructure.Common (2)
InMemory.FunctionalTests (270)
ChunkedRequestTests.cs (9)
184await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
297await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
428await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
603await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
676await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
720await response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello World"), 0, 11);
934await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
986await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
1097await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
ChunkedResponseTests.cs (36)
27await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello "), 0, 6));
28await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("World!"), 0, 6));
91await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello "), 0, 6));
92await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("World!"), 0, 6));
204Encoding.ASCII.GetBytes(expectedString).CopyTo(memory);
245Encoding.ASCII.GetBytes(expectedString).CopyTo(memory);
317await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello "), 0, 6));
319await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("World!"), 0, 6));
427await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World!"), 0, 12));
494await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello "), 0, 6));
499await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("World!"), 0, 6));
540await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("6\r\nHello \r\n"), 0, 11));
541await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("6\r\nWorld!\r\n"), 0, 11));
542await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("0\r\n\r\n"), 0, 5));
579var fisrtPartOfResponse = Encoding.ASCII.GetBytes("Hello ");
584var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
622var fisrtPartOfResponse = Encoding.ASCII.GetBytes("Hello ");
627var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
670var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', memory.Length));
675var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
726var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', memory.Length));
731var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
782var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', length));
788var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
834var fisrtPartOfResponse = Encoding.ASCII.GetBytes("Hello ");
838var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
878var fisrtPartOfResponse = Encoding.ASCII.GetBytes("Hello ");
882var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
924var fisrtPartOfResponse = Encoding.ASCII.GetBytes("Hello ");
962var fisrtPartOfResponse = Encoding.ASCII.GetBytes("Hello ");
1077var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', writeSize));
1116var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', writeSize));
1151var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
1154var secondPartOfResponse = Encoding.ASCII.GetBytes(" world");
1158await response.Body.WriteAsync(Encoding.ASCII.GetBytes("hello, world"));
1159await response.BodyWriter.WriteAsync(Encoding.ASCII.GetBytes("hello, world"));
Http2\Http2StreamTests.cs (61)
193await SendDataAsync(1, Encoding.UTF8.GetBytes("Hello World"), endStream: true);
215Assert.Equal("Hello World", Encoding.UTF8.GetString(dataFrame.Payload.Span));
244await SendDataAsync(1, Encoding.UTF8.GetBytes("Hello World"), endStream: true);
266Assert.Equal("Hello World", Encoding.UTF8.GetString(dataFrame.Payload.Span));
2180_serviceContext.ServerOptions.ResponseHeaderEncodingSelector = _ => Encoding.UTF8;
2181_serviceContext.ServerOptions.RequestHeaderEncodingSelector = _ => Encoding.UTF8; // Used for decoding response.
2223var encoding = Encoding.GetEncoding(Encoding.Latin1.CodePage, EncoderFallback.ExceptionFallback,
2506_serviceContext.ServerOptions.ResponseHeaderEncodingSelector = _ => Encoding.UTF8;
2507_serviceContext.ServerOptions.RequestHeaderEncodingSelector = _ => Encoding.UTF8; // Used for decoding response.
2558var encoding = Encoding.GetEncoding(Encoding.Latin1.CodePage, EncoderFallback.ExceptionFallback,
3878var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
3883var secondPartOfResponse = Encoding.ASCII.GetBytes(" world");
3925var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
3930var secondPartOfResponse = Encoding.ASCII.GetBytes(" world");
3972var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', memory.Length));
3977var secondPartOfResponse = Encoding.ASCII.GetBytes("aaaaaa");
4006Assert.Equal(Encoding.ASCII.GetBytes(new string('a', 4102)), dataFrame.PayloadSequence.ToArray());
4025var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', memory.Length));
4030var secondPartOfResponse = Encoding.ASCII.GetBytes("aaaaaa");
4059Assert.Equal(Encoding.ASCII.GetBytes(new string('a', 4102)), dataFrame.PayloadSequence.ToArray());
4078var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
4082var secondPartOfResponse = Encoding.ASCII.GetBytes(" world");
4126var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
4130var secondPartOfResponse = Encoding.ASCII.GetBytes(" world");
4172var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
4299var payload = Encoding.ASCII.GetBytes("hello,");
4332var payload = Encoding.ASCII.GetBytes("hello,");
4336var secondPayload = Encoding.ASCII.GetBytes(" world");
4376var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
4379var secondPartOfResponse = Encoding.ASCII.GetBytes(" world");
4385await response.Body.WriteAsync(Encoding.ASCII.GetBytes("hello, world"));
4386await response.BodyWriter.WriteAsync(Encoding.ASCII.GetBytes("hello, world"));
4444var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
4448var secondPartOfResponse = Encoding.ASCII.GetBytes(" world");
4492var fisrtPartOfResponse = Encoding.ASCII.GetBytes("Hello ");
4496var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
4535await httpContext.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("hello, world"));
4578var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
4581var secondPartOfResponse = Encoding.ASCII.GetBytes(" world\r\n");
4585await response.Body.WriteAsync(Encoding.ASCII.GetBytes("hello, world\r\n"));
4586await response.BodyWriter.WriteAsync(Encoding.ASCII.GetBytes("hello, world\r\n"));
4964Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5088Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5156var length = Encoding.UTF8.GetBytes("Hello World", buffer.Span);
5206Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5280Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5357Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5428Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5506Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5595Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5682Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5774Assert.Equal("Hello World", Encoding.UTF8.GetString(bodyFrame.Payload.Span));
5798_serviceContext.ServerOptions.RequestHeaderEncodingSelector = _ => Encoding.Latin1;
5841var encoding = Encoding.GetEncoding(Encoding.ASCII.CodePage, EncoderFallback.ExceptionFallback,
5924var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new String('a', sizeHint));
Http3\Http3StreamTests.cs (41)
36await requestStream.SendDataAsync(Encoding.ASCII.GetBytes("Hello world"), endStream: true);
42Assert.Equal("Hello world", Encoding.ASCII.GetString(responseData.ToArray()));
675Assert.Equal("Hello world", Encoding.ASCII.GetString(responseData.ToArray()));
769var payload = Encoding.ASCII.GetBytes("hello world");
800var payload = Encoding.ASCII.GetBytes("hello,");
804var secondPayload = Encoding.ASCII.GetBytes(" world");
811Assert.Equal("hello,", Encoding.UTF8.GetString(response.Span));
814Assert.Equal(" world", Encoding.UTF8.GetString(secondResponse.Span));
873Assert.Equal("Hello World", Encoding.ASCII.GetString(responseData.ToArray()));
891_serviceContext.ServerOptions.ResponseHeaderEncodingSelector = _ => Encoding.UTF8;
892_serviceContext.ServerOptions.RequestHeaderEncodingSelector = _ => Encoding.UTF8; // Used for decoding response.
907Assert.Equal("Hello World", Encoding.ASCII.GetString(responseData.ToArray()));
927var encoding = Encoding.GetEncoding(Encoding.Latin1.CodePage, EncoderFallback.ExceptionFallback,
966Assert.Equal("Hello world", Encoding.ASCII.GetString(responseData.ToArray()));
1025Assert.Equal("Hello World", Encoding.ASCII.GetString(responseData.ToArray()));
1040_serviceContext.ServerOptions.ResponseHeaderEncodingSelector = _ => Encoding.UTF8;
1041_serviceContext.ServerOptions.RequestHeaderEncodingSelector = _ => Encoding.UTF8; // Used for decoding response.
1056Assert.Equal("Hello World", Encoding.ASCII.GetString(responseData.ToArray()));
1078var encoding = Encoding.GetEncoding(Encoding.Latin1.CodePage, EncoderFallback.ExceptionFallback,
1090Assert.Equal("Hello World", Encoding.ASCII.GetString(responseData.ToArray()));
1316Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1419Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1485var length = Encoding.UTF8.GetBytes("Hello World", buffer.Span);
1515Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1570Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1628Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1686Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1744Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1808Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1869Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1937Assert.Equal("Hello World", Encoding.UTF8.GetString(data.Span));
1961await requestStream.SendDataAsync(Encoding.UTF8.GetBytes("This is invalid."));
1989await requestStream.SendDataAsync(Encoding.UTF8.GetBytes("Hello world"));
2023await requestStream.SendDataAsync(Encoding.UTF8.GetBytes("Hello world"));
2025await requestStream.SendDataAsync(Encoding.UTF8.GetBytes("This is invalid."));
2073await requestStream.SendDataAsync(Encoding.UTF8.GetBytes("Hello world"));
3090var sendTask = requestStream.SendDataAsync(Encoding.ASCII.GetBytes(new string('a', sendSize)));
RequestTests.cs (16)
123Assert.Equal("Hello ", Encoding.ASCII.GetString(data));
189dataRead = Encoding.ASCII.GetString(data) == "abc";
594Assert.Equal(identifierLength, Encoding.ASCII.GetByteCount(context.TraceIdentifier));
1602var response = Encoding.ASCII.GetBytes("goodbye");
1650var response = Encoding.ASCII.GetBytes("hello");
1710Assert.Equal("Hello", Encoding.ASCII.GetString(buffer, 0, 5));
1753Assert.Equal("Hello", Encoding.ASCII.GetString(buffer, 0, 5));
1801Assert.Equal("Hello", Encoding.ASCII.GetString(buffer));
1843Assert.Equal("Hello", Encoding.ASCII.GetString(buffer, 0, 5));
1923await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
1969await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
2052await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
2197testContext.ServerOptions.RequestHeaderEncodingSelector = _ => Encoding.Latin1;
2290testContext.ServerOptions.RequestHeaderEncodingSelector = _ => Encoding.UTF32;
2305await connection.Stream.WriteAsync(Encoding.UTF32.GetBytes("£")).DefaultTimeout();
2353var writer = new StreamWriter(client.Stream, Encoding.GetEncoding("iso-8859-1"));
ResponseTests.cs (48)
222var payload = Encoding.ASCII.GetBytes("hello world");
249var payload = Encoding.ASCII.GetBytes("hello,");
253var secondPayload = Encoding.ASCII.GetBytes(" world");
566$"HTTP/1.1 {Encoding.ASCII.GetString(ReasonPhrases.ToStatusBytes(statusCode))}",
742$"HTTP/1.1 {Encoding.ASCII.GetString(ReasonPhrases.ToStatusBytes(statusCode))}",
823$"HTTP/1.1 {Encoding.ASCII.GetString(ReasonPhrases.ToStatusBytes(statusCode))}",
960await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("hello,"), 0, 6));
961await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes(" world"), 0, 6));
1039var response = Encoding.ASCII.GetBytes("hello, world");
1074var response = Encoding.ASCII.GetBytes("hello, world");
1504httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello, world"), 0, 12);
1537httpContext.Response.Body.Write(Encoding.ASCII.GetBytes("hello, world"), 0, 12);
1908var response = Encoding.ASCII.GetBytes("hello, world");
1950var response = Encoding.ASCII.GetBytes("hello, world");
1992var response = Encoding.ASCII.GetBytes("hello, world");
2037var response = Encoding.ASCII.GetBytes("hello, world");
2080var response = Encoding.ASCII.GetBytes("hello, world");
2120var response = Encoding.ASCII.GetBytes("hello, world");
2518using (var reader = new StreamReader(request.Body, Encoding.ASCII))
2566var response = Encoding.ASCII.GetBytes("hello, world");
2739await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
2785await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
2832await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
2878await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
2923await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello"), 0, 5));
2958await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello World"), 0, 11));
3428var encoder = Encoding.ASCII.GetEncoder();
3429var encodedLength = Encoding.ASCII.GetByteCount(expectedString);
3612var ioEx = Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(Encoding.ASCII.GetBytes("What!?"), 0, 6));
3614await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello1"), 0, 6);
3640context.Response.Body.Write(Encoding.ASCII.GetBytes("Hello1"), 0, 6);
3671context.Response.Body.Write(Encoding.ASCII.GetBytes("Hello!"), 0, 6);
3708var ioEx = Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(Encoding.ASCII.GetBytes("What!?"), 0, 6));
3711return context.Response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello!"), 0, 6)).AsTask();
3866var fisrtPartOfResponse = Encoding.ASCII.GetBytes("Hello ");
3870var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
3906var fisrtPartOfResponse = Encoding.ASCII.GetBytes("Hello ");
3910var secondPartOfResponse = Encoding.ASCII.GetBytes("World!");
3938await httpContext.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("hello, world"));
3967var fisrtPartOfResponse = Encoding.ASCII.GetBytes("hello,");
3970var secondPartOfResponse = Encoding.ASCII.GetBytes(" world\r\n");
3974await response.Body.WriteAsync(Encoding.ASCII.GetBytes("hello, world\r\n"));
3975await response.BodyWriter.WriteAsync(Encoding.ASCII.GetBytes("hello, world\r\n"));
4103Encoding.ASCII.GetBytes("a").CopyTo(memory);
4149Encoding.ASCII.GetBytes("a").CopyTo(memory);
4202Encoding.ASCII.GetBytes("a").CopyTo(memory);
4209Encoding.ASCII.GetBytes("a").CopyTo(memory);
4898using (var reader = new StreamReader(connection.Stream, Encoding.ASCII, detectEncodingFromByteOrderMarks: true, bufferSize: 1024, leaveOpen: true))
InProcessWebSite (10)
src\Servers\IIS\IIS\test\testassets\InProcessWebSite\Startup.cs (6)
635await ctx.Response.WriteAsync(Encoding.UTF8.GetString(readBuffer, 0, result));
648await ctx.Response.WriteAsync(Encoding.UTF8.GetString(readBuffer, 0, result));
741await ctx.Response.WriteAsync(Encoding.UTF8.GetString(readBuffer, 0, result));
743await ctx.Response.WriteAsync(Encoding.UTF8.GetString(readBuffer, 0, result));
778await ctx.Response.WriteAsync(Encoding.UTF8.GetString(buffer));
963await fileStream.WriteAsync(Encoding.UTF8.GetBytes(fileContent), 0, fileContent.Length);
Interop.FunctionalTests (8)
Http2WebSocketInteropTests.cs (4)
68Assert.Equal("Hello", Encoding.UTF8.GetString(bytes, 0, result.Count));
70await ws.SendAsync(Encoding.UTF8.GetBytes("Hi there"), WebSocketMessageType.Text, endOfMessage: true, default);
86await wsClient.SendAsync(Encoding.UTF8.GetBytes("Hello"), WebSocketMessageType.Text, endOfMessage: true, default);
92Assert.Equal("Hi there", Encoding.UTF8.GetString(bytes, 0, result.Count));
IOperationGenerator (2)
LargeResponseApp (1)
Metrics (4)
Metrics.Legacy (4)
Microsoft.Arcade.Common (2)
Microsoft.Arcade.Test.Common (1)
Microsoft.AspNetCore.Antiforgery (3)
Microsoft.AspNetCore.App.Analyzers.Test (1)
Microsoft.AspNetCore.Authentication.Facebook (2)
Microsoft.AspNetCore.Authentication.JwtBearer.Tools.Tests (2)
Microsoft.AspNetCore.Authentication.MicrosoftAccount (1)
Microsoft.AspNetCore.Authentication.Negotiate (2)
Microsoft.AspNetCore.Authentication.OAuth (1)
Microsoft.AspNetCore.Authentication.OpenIdConnect (5)
Microsoft.AspNetCore.Authentication.Test (38)
Microsoft.AspNetCore.Authentication.Twitter (2)
Microsoft.AspNetCore.Components (5)
Microsoft.AspNetCore.Components.Endpoints (12)
Microsoft.AspNetCore.Components.Endpoints.Tests (8)
Binding\FormDataMapperTests.cs (6)
2011var expected = new FormFileCollection { new FormFile(new MemoryStream(Encoding.UTF8.GetBytes(expectedString)), 0, expectedString.Length, "file", "file.txt") };
2031Assert.Equal(expectedString, Encoding.UTF8.GetString(buffer, 0, buffer.Length));
2042new FormFile(new MemoryStream(Encoding.UTF8.GetBytes(expectedString1)), 0, expectedString1.Length, "file", "file1.txt"),
2043new FormFile(new MemoryStream(Encoding.UTF8.GetBytes(expectedString2)), 0, expectedString2.Length, "file", "file2.txt")
2066Assert.Equal(expectedString1, Encoding.UTF8.GetString(buffer1, 0, buffer1.Length));
2073Assert.Equal(expectedString1, Encoding.UTF8.GetString(buffer2, 0, buffer2.Length));
Microsoft.AspNetCore.Components.Server (4)
Microsoft.AspNetCore.Components.Server.Tests (11)
Microsoft.AspNetCore.Components.Web.Tests (1)
Microsoft.AspNetCore.Components.WebAssembly.Server (5)
Microsoft.AspNetCore.Components.WebView (2)
Microsoft.AspNetCore.Components.WebView.Maui (1)
Microsoft.AspNetCore.Components.WebView.Test (1)
Microsoft.AspNetCore.Components.WebView.WindowsForms (1)
Microsoft.AspNetCore.Components.WebView.Wpf (1)
Microsoft.AspNetCore.Cryptography.Internal.Tests (2)
Microsoft.AspNetCore.Cryptography.KeyDerivation (5)
Microsoft.AspNetCore.Cryptography.KeyDerivation.Tests (3)
Microsoft.AspNetCore.DataProtection (1)
Microsoft.AspNetCore.DataProtection.Extensions.Tests (3)
Microsoft.AspNetCore.DataProtection.Tests (57)
Microsoft.AspNetCore.DeveloperCertificates.XPlat (5)
Microsoft.AspNetCore.DeveloperCertificates.XPlat.Tests (4)
Microsoft.AspNetCore.Diagnostics (2)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore (2)
Microsoft.AspNetCore.Diagnostics.HealthChecks (3)
Microsoft.AspNetCore.Diagnostics.Tests (1)
Microsoft.AspNetCore.Grpc.JsonTranscoding (13)
Internal\JsonRequestHelpers.cs (9)
56public static (Stream stream, bool usesTranscodingStream) GetStream(Stream innerStream, Encoding? encoding)
58if (encoding == null || encoding.CodePage == Encoding.UTF8.CodePage)
63var stream = Encoding.CreateTranscodingStream(innerStream, encoding, Encoding.UTF8, leaveOpen: true);
67public static Encoding? GetEncodingFromCharset(StringSegment charset)
73return Encoding.UTF8;
79return charset.HasValue ? Encoding.GetEncoding(charset.Value) : null;
87public static async ValueTask SendErrorResponse(HttpResponse response, Encoding encoding, Metadata trailers, Status status, JsonSerializerOptions options)
166public static async ValueTask WriteResponseMessage(HttpResponse response, Encoding encoding, object responseBody, JsonSerializerOptions options, CancellationToken cancellationToken)
Microsoft.AspNetCore.Grpc.JsonTranscoding.Tests (20)
Microsoft.AspNetCore.Hosting (1)
Microsoft.AspNetCore.Http (6)
Microsoft.AspNetCore.Http.Abstractions (7)
Extensions\HttpResponseWritingExtensions.cs (7)
31return response.WriteAsync(text, Encoding.UTF8, cancellationToken);
43public static Task WriteAsync(this HttpResponse response, string text, Encoding encoding, CancellationToken cancellationToken = default(CancellationToken))
64private static async Task StartAndWriteAsyncAwaited(this HttpResponse response, string text, Encoding encoding, CancellationToken cancellationToken, Task startAsyncTask)
71private static void Write(this HttpResponse response, string text, Encoding encoding)
90private static int GetEncodingMaxByteSize(Encoding encoding)
92if (encoding == Encoding.UTF8)
100private static void WriteMultiSegmentEncoded(PipeWriter writer, string text, Encoding encoding, Span<byte> destination, int encodedLength, int minimumByteSize)
Microsoft.AspNetCore.Http.Abstractions.Tests (18)
Microsoft.AspNetCore.Http.Connections.Common (1)
Microsoft.AspNetCore.Http.Connections.Tests (62)
HttpConnectionDispatcherTests.cs (36)
70var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
95var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
122var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
159var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
187var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
215var bytes = Encoding.UTF8.GetBytes("EXTRADATA Hi");
245Assert.Equal("Hi", Encoding.UTF8.GetString(result.Buffer.ToArray()));
274var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
322Assert.Equal("No Connection with that ID", Encoding.UTF8.GetString(strm.ToArray()));
363Assert.Equal("No Connection with that ID", Encoding.UTF8.GetString(strm.ToArray()));
401Assert.Equal("POST requests are not allowed for WebSocket connections.", Encoding.UTF8.GetString(strm.ToArray()));
585var bytes = Encoding.UTF8.GetBytes("Hello World");
613Assert.Equal("Hello World", Encoding.UTF8.GetString(result.Buffer.ToArray()));
649var bytes = Encoding.UTF8.GetBytes("Hello World");
796var buffer = Encoding.UTF8.GetBytes("Hello World");
871Assert.Equal("Connection ID required", Encoding.UTF8.GetString(strm.ToArray()));
945Assert.Equal("Connection ID required", Encoding.UTF8.GetString(strm.ToArray()));
1655var buffer = Encoding.UTF8.GetBytes("Hello World");
1690var buffer = Encoding.UTF8.GetBytes("Hello World");
1731var buffer = Encoding.UTF8.GetBytes("Hello World");
1775await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello, World"));
1863await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Unblock")).AsTask().DefaultTimeout();
1915await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Unblock")).AsTask().DefaultTimeout();
2045Assert.Equal("Cannot terminate this connection using the DELETE endpoint.", Encoding.UTF8.GetString(ms.ToArray()));
2223await c.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Message1")).DefaultTimeout();
2226await c.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Message2")).DefaultTimeout();
2242Assert.Equal("Message1", Encoding.UTF8.GetString(ms.ToArray()));
2252Assert.Equal("Message2", Encoding.UTF8.GetString(ms.ToArray()));
2276var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
2302var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
2331var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
2360var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
2575var buffer = Encoding.UTF8.GetBytes("Hello, world");
2635var buffer = Encoding.UTF8.GetBytes("Hello, world");
2692var buffer = Encoding.UTF8.GetBytes("Hello, world");
3723Assert.Equal($"{transportType} transport not supported by this end point type", Encoding.UTF8.GetString(strm.ToArray()));
Microsoft.AspNetCore.Http.Extensions (14)
Microsoft.AspNetCore.Http.Extensions.Tests (70)
RequestDelegateGenerator\CompileTimeCreationTests.cs (10)
56project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
57project = project.AddDocument("OtherTestMapActions.cs", SourceText.From(otherSource, Encoding.UTF8)).Project;
82project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
83project = project.AddDocument("OtherTestMapActions.cs", SourceText.From(otherSource, Encoding.UTF8)).Project;
165project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8), filePath: Path.Combine(currentDirectory, "TestMapActions.cs")).Project;
232project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
286project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
333project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
669project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
726project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
RequestDelegateGenerator\RequestDelegateCreationTests.Forms.cs (16)
25var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
60var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
95var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
133var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
169var fileContent1 = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
170var fileContent2 = new StringContent("there", Encoding.UTF8, "application/octet-stream");
212var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
249var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
285var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
358var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
392var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
441var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
481var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
818var fileContent = new StringContent("hello", Encoding.UTF8, "application/octet-stream");
964httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(new string('x', 2049)));
1001httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(new string('x', 2049)));
Microsoft.AspNetCore.Http.Microbenchmarks (4)
Microsoft.AspNetCore.Http.Results (25)
Results.cs (8)
87/// This is equivalent to <see cref="Text(string?, string?, Encoding?)"/>.
98public static IResult Content(string? content, string? contentType, Encoding? contentEncoding)
104/// This is equivalent to <see cref="Text(string?, string?, Encoding?, int?)"/>.
116public static IResult Content(string? content, string? contentType = null, Encoding? contentEncoding = null, int? statusCode = null)
122/// This is an alias for <see cref="Content(string?, string?, Encoding?)"/>.
133public static IResult Text(string? content, string? contentType, Encoding? contentEncoding)
139/// This is an alias for <see cref="Content(string?, string?, Encoding?, int?)"/>.
151public static IResult Text(string? content, string? contentType = null, Encoding? contentEncoding = null, int? statusCode = null)
TypedResults.cs (8)
91/// This is equivalent to <see cref="Text(string?, string?, Encoding?)"/>.
102public static ContentHttpResult Content(string? content, string? contentType, Encoding? contentEncoding)
108/// This is equivalent to <see cref="Text(string?, string?, Encoding?, int?)"/>.
120public static ContentHttpResult Content(string? content, string? contentType = null, Encoding? contentEncoding = null, int? statusCode = null)
126/// This is an alias for <see cref="Content(string?, string?, Encoding?)"/>.
137public static ContentHttpResult Text(string? content, string? contentType, Encoding? contentEncoding)
153/// This is an alias for <see cref="Content(string?, string?, Encoding?, int?)"/>.
165public static ContentHttpResult Text(string? content, string? contentType = null, Encoding? contentEncoding = null, int? statusCode = null)
Microsoft.AspNetCore.Http.Results.Tests (62)
Microsoft.AspNetCore.Http.Tests (32)
Microsoft.AspNetCore.Http.ValidationsGenerator (1)
Microsoft.AspNetCore.HttpLogging (20)
Microsoft.AspNetCore.HttpLogging.Tests (21)
Microsoft.AspNetCore.Identity (5)
Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test (1)
Microsoft.AspNetCore.Identity.FunctionalTests (1)
Microsoft.AspNetCore.Identity.InMemory.Test (2)
Microsoft.AspNetCore.Identity.Test (1)
Microsoft.AspNetCore.Identity.UI (20)
Microsoft.AspNetCore.InternalTesting (3)
Microsoft.AspNetCore.InternalTesting.Tests (1)
Microsoft.AspNetCore.Mvc.Abstractions (5)
Microsoft.AspNetCore.Mvc.ApiExplorer.Test (1)
Microsoft.AspNetCore.Mvc.Core (82)
Microsoft.AspNetCore.Mvc.Core.Test (163)
Formatters\JsonOutputFormatterTestBase.cs (10)
86var encoding = CreateOrGetSupportedEncoding(formatter, encodingAsString, isDefaultEncoding);
101await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding(encodingAsString));
118var encoding = CreateOrGetSupportedEncoding(formatter, "utf-8", isDefaultEncoding: true);
133await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8"));
150await Record.ExceptionAsync(() => jsonFormatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.UTF8));
158var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
179Func<Stream, Encoding, TextWriter> writerFactory = null)
194protected static Encoding CreateOrGetSupportedEncoding(
199Encoding encoding = null;
208encoding = Encoding.GetEncoding(encodingAsString);
Formatters\SystemTextJsonOutputFormatterTest.cs (11)
40var encoding = CreateOrGetSupportedEncoding(formatter, "utf-8", isDefaultEncoding: true);
55await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8"));
68var encoding = CreateOrGetSupportedEncoding(formatter, "utf-16", isDefaultEncoding: true);
83await Assert.ThrowsAsync<TimeZoneNotFoundException>(() => formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-16")));
94var encoding = CreateOrGetSupportedEncoding(formatter, "utf-8", isDefaultEncoding: true);
110await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8"));
140await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8"));
186var encoding = CreateOrGetSupportedEncoding(formatter, "utf-8", isDefaultEncoding: true);
201await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8"));
226var encoding = CreateOrGetSupportedEncoding(formatter, "utf-8", isDefaultEncoding: true);
241await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8"));
ModelBinding\Binders\BodyModelBinderTests.cs (18)
253httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("Bad data!"));
301httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("Bad data!"));
330httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("Bad data!"));
372httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("Bad data!"));
401httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("Bad data!"));
448httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("valid data!"));
483httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("valid data!"));
512httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("valid data"));
725private readonly Func<InputFormatterContext, Encoding, Task<InputFormatterResult>> _readRequestBodyAsync;
727public XyzFormatter(Func<InputFormatterContext, Encoding, Task<InputFormatterResult>> readRequestBodyAsync)
730SupportedEncodings.Add(Encoding.UTF8);
741Encoding effectiveEncoding)
783public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
805public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
827public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
853public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
875public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
895public override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
Microsoft.AspNetCore.Mvc.Core.TestCommon (2)
Microsoft.AspNetCore.Mvc.Formatters.Xml (14)
Microsoft.AspNetCore.Mvc.Formatters.Xml.Test (64)
Microsoft.AspNetCore.Mvc.FunctionalTests (50)
ConsumesAttributeTestsBase.cs (5)
102request.Content = new StringContent(input, Encoding.UTF8, requestContentType);
123request.Content = new StringContent(input, Encoding.UTF8, requestContentType);
147request.Content = new StringContent(input, Encoding.UTF8, "application/xml");
168request.Content = new StringContent(input, Encoding.UTF8, "application/vnd.example+json");
191request.Content = new StringContent(input, Encoding.UTF8, "application/vnd.example+xml");
InputObjectValidationTests.cs (12)
75var content = new StringContent(input, Encoding.UTF8, "application/xml");
97var content = new StringContent(input, Encoding.UTF8, "application/json");
118var content = new StringContent("{\"Alias\":\"xyz\"}", Encoding.UTF8, "application/json");
134var content = new StringContent(requestData, Encoding.UTF8, "application/json");
164var content = new StringContent(requestContent, Encoding.UTF8, "application/json");
204var content = new StringContent(invalidRequestData, Encoding.UTF8, "application/json");
225var content = new StringContent(invalidRequestData, Encoding.UTF8, "application/json");
245var content = new StringContent(invalidRequestData, Encoding.UTF8, "application/json");
270Content = new StringContent(@"{ ""Id"": ""S-1-5-21-1004336348-1177238915-682003330-512"" }", Encoding.UTF8, "application/json"),
291Content = new StringContent(input, Encoding.UTF8, "application/json"),
320Content = new StringContent(input, Encoding.UTF8, "application/json"),
352Content = new StringContent(input, Encoding.UTF8, "application/xml"),
JsonInputFormatterTestBase.cs (6)
47var content = new StringContent(input, Encoding.UTF8, requestContentType);
66var content = new StringContent(jsonInput, Encoding.UTF8, requestContentType);
84var content = new StringContent(input, Encoding.UTF8, "application/json");
100var content = new StringContent(expected, Encoding.UTF8, "application/json");
203var content = new StringContent(jsonInput, Encoding.UTF8, "application/json");
222var content = new StringContent(jsonInput, Encoding.UTF8, requestContentType);
Microsoft.AspNetCore.Mvc.IntegrationTests (43)
Microsoft.AspNetCore.Mvc.NewtonsoftJson (14)
Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test (90)
NewtonsoftJsonOutputFormatterTest.cs (22)
80await jsonFormatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.UTF8);
112await jsonFormatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.UTF8);
136await jsonFormatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.UTF8);
144var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
159await jsonFormatter.WriteResponseBodyAsync(outputFormatterContext1, Encoding.UTF8);
168await jsonFormatter.WriteResponseBodyAsync(outputFormatterContext2, Encoding.UTF8);
176var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
211await formatter.WriteResponseBodyAsync(context, Encoding.UTF8);
219var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
263await formatter.WriteResponseBodyAsync(context, Encoding.UTF8);
271var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
299await formatter.WriteResponseBodyAsync(context, Encoding.UTF8);
307var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
334await formatter.WriteResponseBodyAsync(context, Encoding.UTF8);
342var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
360await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.UTF8);
390await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.UTF8);
421await formatter.WriteResponseBodyAsync(context, Encoding.UTF8);
429var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
459await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8"));
503await Assert.ThrowsAsync<OperationCanceledException>(() => formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8")));
538await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8"));
src\Mvc\Mvc.Core\test\Formatters\JsonOutputFormatterTestBase.cs (10)
86var encoding = CreateOrGetSupportedEncoding(formatter, encodingAsString, isDefaultEncoding);
101await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding(encodingAsString));
118var encoding = CreateOrGetSupportedEncoding(formatter, "utf-8", isDefaultEncoding: true);
133await formatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.GetEncoding("utf-8"));
150await Record.ExceptionAsync(() => jsonFormatter.WriteResponseBodyAsync(outputFormatterContext, Encoding.UTF8));
158var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();
179Func<Stream, Encoding, TextWriter> writerFactory = null)
194protected static Encoding CreateOrGetSupportedEncoding(
199Encoding encoding = null;
208encoding = Encoding.GetEncoding(encodingAsString);
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (1)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.Test (2)
Microsoft.AspNetCore.Mvc.Razor.Test (2)
Microsoft.AspNetCore.Mvc.RazorPages (2)
Microsoft.AspNetCore.Mvc.RazorPages.Test (6)
Microsoft.AspNetCore.Mvc.TagHelpers (6)
Microsoft.AspNetCore.Mvc.TagHelpers.Test (11)
Microsoft.AspNetCore.Mvc.Testing.Tasks (1)
Microsoft.AspNetCore.Mvc.ViewFeatures (12)
Microsoft.AspNetCore.Mvc.ViewFeatures.Test (21)
Microsoft.AspNetCore.Mvc.Views.TestCommon (4)
Microsoft.AspNetCore.OpenApi (1)
Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests (4)
Microsoft.AspNetCore.OpenApi.Tests (6)
Microsoft.AspNetCore.OutputCaching (4)
Microsoft.AspNetCore.OutputCaching.StackExchangeRedis (3)
Microsoft.AspNetCore.OutputCaching.Tests (5)
Microsoft.AspNetCore.Owin (1)
Microsoft.AspNetCore.Razor (2)
Microsoft.AspNetCore.RequestDecompression.Tests (1)
Microsoft.AspNetCore.ResponseCaching.Tests (1)
Microsoft.AspNetCore.Rewrite (1)
Microsoft.AspNetCore.Routing (9)
Microsoft.AspNetCore.Routing.Tests (7)
Microsoft.AspNetCore.Server.HttpSys (10)
Microsoft.AspNetCore.Server.HttpSys.FunctionalTests (68)
Listener\RequestHeaderTests.cs (8)
25Task responseTask = SendRequestAsync(address, "Custom-Header", customValues, Encoding.UTF8);
66Task responseTask = SendRequestAsync(address, "Custom-Header", customValues, Encoding.UTF8);
93Task responseTask = SendRequestAsync(address, "Custom-Header", customValues, Encoding.Latin1);
121Task responseTask = SendRequestAsync(address, "Custom-Header", customValues, Encoding.Latin1);
149var responseTask = SendRequestAsync(address, "Custom-Header", customValues, Encoding.Latin1);
162Task responseTask = SendRequestAsync(address, "If-None-Match", customValues, Encoding.UTF8);
187Task responseTask = SendRequestAsync(address, "Custom-Header", customValues, Encoding.UTF8);
205private async Task<string> SendRequestAsync(string address, string customHeader, string[] customValues, Encoding encoding)
src\Shared\runtime\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
Microsoft.AspNetCore.Server.HttpSys.Microbenchmarks (3)
Microsoft.AspNetCore.Server.HttpSys.Tests (6)
Microsoft.AspNetCore.Server.IIS (15)
Microsoft.AspNetCore.Server.IntegrationTesting.IIS (1)
Microsoft.AspNetCore.Server.Kestrel.Core (84)
src\Shared\runtime\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
src\Shared\runtime\Http3\QPack\QPackEncoder.cs (9)
66public static bool EncodeLiteralHeaderFieldWithStaticNameReference(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
89/// Encodes just the name part of a Literal Header Field With Static Name Reference. Must call <see cref="EncodeValueString(string, Encoding?, Span{byte}, out int)"/> after to encode the header's value.
130public static bool EncodeLiteralHeaderFieldWithoutNameReference(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
147public static bool EncodeLiteralHeaderFieldWithoutNameReference(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
160/// Encodes just the value part of a Literawl Header Field Without Static Name Reference. Must call <see cref="EncodeValueString(string, Encoding?, Span{byte}, out int)"/> after to encode the header's value.
182private static bool EncodeValueString(string s, Encoding? valueEncoding, Span<byte> buffer, out int length)
188int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
220public static bool EncodeValueString(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> buffer, out int length)
239if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
Microsoft.AspNetCore.Server.Kestrel.Core.Tests (228)
src\Shared\test\Shared.Tests\runtime\Http2\HuffmanDecodingTests.cs (14)
193{ new byte[] { 0x07 }, Encoding.ASCII.GetBytes("0") },
195{ new byte[] { 0x57 }, Encoding.ASCII.GetBytes("%") },
197{ new byte[] { 0xb9 }, Encoding.ASCII.GetBytes(":") },
199{ new byte[] { 0xf8 }, Encoding.ASCII.GetBytes("&") },
201{ new byte[] { 0xfe, 0x3f }, Encoding.ASCII.GetBytes("!") },
203{ new byte[] { 0xff, 0x7f }, Encoding.ASCII.GetBytes("+") },
205{ new byte[] { 0xff, 0xaf }, Encoding.ASCII.GetBytes("#") },
207{ new byte[] { 0xff, 0xcf }, Encoding.ASCII.GetBytes("$") },
209{ new byte[] { 0xff, 0xf3 }, Encoding.ASCII.GetBytes("^") },
211{ new byte[] { 0xff, 0xf9 }, Encoding.ASCII.GetBytes("<") },
213{ new byte[] { 0xff, 0xfe, 0x1f }, Encoding.ASCII.GetBytes("\\") },
236{ new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1111 }, Encoding.ASCII.GetBytes("hello") },
239{ new byte[] { 0xb6, 0xb9, 0xac, 0x1c, 0x85, 0x58, 0xd5, 0x20, 0xa4, 0xb6, 0xc2, 0xad, 0x61, 0x7b, 0x5a, 0x54, 0x25, 0x1f }, Encoding.ASCII.GetBytes("upgrade-insecure-requests") },
240{ new byte[] { 0xfe, 0x53 }, Encoding.ASCII.GetBytes("\"t") },
Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks (52)
Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes (2)
Microsoft.AspNetCore.Server.Kestrel.Transport.Quic (4)
Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests (4)
Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets (2)
Microsoft.AspNetCore.Session (4)
Microsoft.AspNetCore.Shared.Tests (106)
runtime\Http2\HuffmanDecodingTests.cs (14)
193{ new byte[] { 0x07 }, Encoding.ASCII.GetBytes("0") },
195{ new byte[] { 0x57 }, Encoding.ASCII.GetBytes("%") },
197{ new byte[] { 0xb9 }, Encoding.ASCII.GetBytes(":") },
199{ new byte[] { 0xf8 }, Encoding.ASCII.GetBytes("&") },
201{ new byte[] { 0xfe, 0x3f }, Encoding.ASCII.GetBytes("!") },
203{ new byte[] { 0xff, 0x7f }, Encoding.ASCII.GetBytes("+") },
205{ new byte[] { 0xff, 0xaf }, Encoding.ASCII.GetBytes("#") },
207{ new byte[] { 0xff, 0xcf }, Encoding.ASCII.GetBytes("$") },
209{ new byte[] { 0xff, 0xf3 }, Encoding.ASCII.GetBytes("^") },
211{ new byte[] { 0xff, 0xf9 }, Encoding.ASCII.GetBytes("<") },
213{ new byte[] { 0xff, 0xfe, 0x1f }, Encoding.ASCII.GetBytes("\\") },
236{ new byte[] { 0b100111_00, 0b101_10100, 0b0_101000_0, 0b0111_1111 }, Encoding.ASCII.GetBytes("hello") },
239{ new byte[] { 0xb6, 0xb9, 0xac, 0x1c, 0x85, 0x58, 0xd5, 0x20, 0xa4, 0xb6, 0xc2, 0xad, 0x61, 0x7b, 0x5a, 0x54, 0x25, 0x1f }, Encoding.ASCII.GetBytes("upgrade-insecure-requests") },
240{ new byte[] { 0xfe, 0x53 }, Encoding.ASCII.GetBytes("\"t") },
src\Shared\runtime\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
src\Shared\runtime\Http3\QPack\QPackEncoder.cs (9)
66public static bool EncodeLiteralHeaderFieldWithStaticNameReference(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
89/// Encodes just the name part of a Literal Header Field With Static Name Reference. Must call <see cref="EncodeValueString(string, Encoding?, Span{byte}, out int)"/> after to encode the header's value.
130public static bool EncodeLiteralHeaderFieldWithoutNameReference(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
147public static bool EncodeLiteralHeaderFieldWithoutNameReference(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
160/// Encodes just the value part of a Literawl Header Field Without Static Name Reference. Must call <see cref="EncodeValueString(string, Encoding?, Span{byte}, out int)"/> after to encode the header's value.
182private static bool EncodeValueString(string s, Encoding? valueEncoding, Span<byte> buffer, out int length)
188int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
220public static bool EncodeValueString(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> buffer, out int length)
239if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
Microsoft.AspNetCore.SignalR.Client.FunctionalTests (2)
Microsoft.AspNetCore.SignalR.Client.SourceGenerator (4)
Microsoft.AspNetCore.SignalR.Client.Tests (24)
Microsoft.AspNetCore.SignalR.Common (3)
Microsoft.AspNetCore.SignalR.Common.Tests (64)
Microsoft.AspNetCore.SignalR.Core (3)
Microsoft.AspNetCore.SignalR.Microbenchmarks (17)
Microsoft.AspNetCore.SignalR.Protocols.Json (2)
Microsoft.AspNetCore.SignalR.Protocols.MessagePack (1)
Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson (3)
Microsoft.AspNetCore.SignalR.StackExchangeRedis (2)
Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests (1)
Microsoft.AspNetCore.SignalR.Tests (38)
HubConnectionHandlerTests.cs (17)
339var part1 = Encoding.UTF8.GetBytes("{\"protocol\": \"json\"");
340var part2 = Encoding.UTF8.GetBytes(",\"version\": 1}");
341var part3 = Encoding.UTF8.GetBytes("\u001e");
382var part1 = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"1\", ");
383var part2 = Encoding.UTF8.GetBytes("\"target\": \"Echo\", \"arguments\"");
384var part3 = Encoding.UTF8.GetBytes(":[\"hello\"]}\u001e");
423var payload = Encoding.UTF8.GetBytes("{\"protocol\": \"json\",\"version\": 1}\u001e{\"type\":1, \"invocationId\":\"1\", \"target\": \"Echo\", \"arguments\":[\"hello\"]}\u001e");
479var payload = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"1\", \"target\": \"Echo\", \"arguments\":[\"hello\"]}\u001e");
508var payload = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"1\", \"target\": \"Echo\", \"arguments\":[\"hello\"]}\u001e");
538var payload1 = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"1\", \"target\": \"Echo\", \"arguments\":[\"one\"]}\u001e");
539var payload2 = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"2\", \"target\": \"Echo\", \"arguments\":[\"two\"]}\u001e");
540var payload3 = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"3\", \"target\": \"Echo\", \"arguments\":[\"three\"]}\u001e");
589var payload1 = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"1\", \"target\": \"Echo\", \"arguments\":[\"one\"]}\u001e");
590var payload2 = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"2\", \"target\": \"Echo\", \"arguments\":[\"two\"]}\u001e");
591var payload3 = Encoding.UTF8.GetBytes("{\"type\":1, \"invocationId\":\"3\", \"target\": \"Echo\", \"arguments\":[\"three\"]}\u001e");
668var payload = Encoding.UTF8.GetBytes("{\"protocol\": \"json\",\"ver");
3566await client.Connection.Application.Output.WriteAsync(Encoding.UTF8.GetBytes(new[] { '{' })).DefaultTimeout();
Microsoft.AspNetCore.SpaProxy (1)
Microsoft.AspNetCore.StaticAssets.Tests (1)
Microsoft.AspNetCore.StaticFiles (1)
Microsoft.AspNetCore.StaticFiles.FunctionalTests (1)
Microsoft.AspNetCore.TestHost.Tests (17)
TestClientTests.cs (12)
128var character = Encoding.ASCII.GetBytes("a");
219Assert.Equal("STARTED", Encoding.UTF8.GetString(buffer, 0, length));
222await requestStream.WriteAsync(Encoding.UTF8.GetBytes("Hello world")).AsTask().DefaultTimeout();
228Assert.Equal("Hello world POST Response", Encoding.UTF8.GetString(buffer, 0, length));
282Assert.Equal("SENT", Encoding.UTF8.GetString(serverBuffer, 0, serverLength));
326await requestStream.WriteAsync(Encoding.UTF8.GetBytes("SENT")).AsTask().DefaultTimeout();
379Assert.Equal("POST Response", Encoding.UTF8.GetString(buffer, 0, length));
386await requestStream.WriteAsync(Encoding.UTF8.GetBytes(new string('!', 1024 * 1024 * 50))).AsTask().DefaultTimeout();
544() => requestStream.WriteAsync(Encoding.UTF8.GetBytes("Hello world")).AsTask(),
616var hello = Encoding.UTF8.GetBytes("hello");
618var world = Encoding.UTF8.GetBytes("world!");
808var hello = Encoding.UTF8.GetBytes("hello");
Microsoft.AspNetCore.Tests (1)
Microsoft.AspNetCore.WebSockets (1)
Microsoft.AspNetCore.WebSockets.Tests (12)
Microsoft.AspNetCore.WebUtilities (29)
Microsoft.AspNetCore.WebUtilities.Microbenchmarks (9)
Microsoft.AspNetCore.WebUtilities.Tests (129)
FormPipeReaderTests.cs (43)
114Assert.Equal(Encoding.UTF8.GetBytes(content), readResult.Buffer.ToArray());
129Assert.Equal(Encoding.UTF8.GetBytes(content), readResult.Buffer.ToArray());
157Assert.Equal(Encoding.UTF8.GetBytes(content), readResult.Buffer.ToArray());
185Assert.Equal(Encoding.UTF8.GetBytes(content), readResult.Buffer.ToArray());
196await bodyPipe.Writer.WriteAsync(Encoding.UTF8.GetBytes(content1));
202await bodyPipe.Writer.WriteAsync(Encoding.UTF8.GetBytes(content2));
210Assert.Equal(Encoding.UTF8.GetBytes("baz=12345678901"), readResult.Buffer.ToArray());
256public void TryParseFormValues_SingleSegmentWorks(Encoding encoding)
274public void TryParseFormValues_Works(Encoding encoding)
293public void TryParseFormValues_LimitsCanBeLarge(Encoding encoding)
315public void TryParseFormValues_SplitAcrossSegmentsWorks(Encoding encoding)
334public void TryParseFormValues_SplitAcrossSegmentsWorks_LimitsCanBeLarge(Encoding encoding)
356public void TryParseFormValues_MultiSegmentWithArrayPoolAcrossSegmentsWorks(Encoding encoding)
374public void TryParseFormValues_MultiSegmentSplitAcrossSegmentsWithPlusesWorks(Encoding encoding)
393public void TryParseFormValues_DecodedPlusesWorks(Encoding encoding)
412public void TryParseFormValues_SplitAcrossSegmentsThatNeedDecodingWorks(Encoding encoding)
431var readOnlySequence = ReadOnlySequenceFactory.CreateSegments(Encoding.UTF8.GetBytes("foo=bar&"), Encoding.UTF8.GetBytes("baz=boo"));
448var readOnlySequence = ReadOnlySequenceFactory.SingleSegmentFactory.CreateWithContent(Encoding.UTF8.GetBytes("foo=bar&baz=boo&t="));
462var readOnlySequence = ReadOnlySequenceFactory.CreateSegments(Encoding.UTF8.GetBytes("fo=bar&ba"), Encoding.UTF8.GetBytes("z=boo&t="));
476var readOnlySequence = ReadOnlySequenceFactory.CreateSegments(Encoding.UTF8.GetBytes("foo=bar&baz=boo&t="));
490var readOnlySequence = ReadOnlySequenceFactory.CreateSegments(Encoding.UTF8.GetBytes("foo=ba&baz=bo"), Encoding.UTF8.GetBytes("o&t="));
504var readOnlySequence = ReadOnlySequenceFactory.CreateSegments(Encoding.UTF8.GetBytes("foo=ba&baz=bo"), Encoding.UTF8.GetBytes("o&asdfasdfasd="));
518var readOnlySequence = ReadOnlySequenceFactory.CreateSegments(Encoding.UTF8.GetBytes("foo=ba&baz=bo"), Encoding.UTF8.GetBytes("o&t=asdfasdfasd"));
534var bytes = Encoding.UTF8.GetBytes("foo=bar&baz=boo");
602{ ReadOnlySequenceFactory.CreateSegments(Encoding.UTF8.GetBytes("fo=bar&b"), Encoding.UTF8.GetBytes("a")) },
603{ new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes("fo=bar&ba")) }
609{ ReadOnlySequenceFactory.CreateSegments(Encoding.UTF8.GetBytes("fo=bar&b"), Encoding.UTF8.GetBytes("=")) },
610{ new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes("fo=bar&b=")) }
613public static TheoryData<Encoding> Encodings =>
614new TheoryData<Encoding>
616{ Encoding.UTF8 },
617{ Encoding.UTF32 },
618{ Encoding.ASCII },
619{ Encoding.Unicode }
629var formContent = Encoding.UTF8.GetBytes(text);
648return Encoding.UTF8.GetBytes(keyValue);
HttpRequestStreamReaderTest.cs (17)
45var reader = new HttpRequestStreamReader(GetLargeStream(), Encoding.UTF8);
57var reader = new HttpRequestStreamReader(stream, Encoding.UTF8);
102var reader = new HttpRequestStreamReader(new MemoryStream(), Encoding.UTF8);
198var reader = new HttpRequestStreamReader(stream, Encoding.UTF8);
222var reader = new HttpRequestStreamReader(stream, Encoding.UTF8, 10);
241var reader = new HttpRequestStreamReader(stream, Encoding.UTF8);
259var reader = new HttpRequestStreamReader(stream, Encoding.UTF8);
344public static void NullInputsInConstructor_ExpectArgumentNullException(Stream stream, Encoding encoding, ArrayPool<byte> bytePool, ArrayPool<char> charPool)
359var httpRequestStreamReader = new HttpRequestStreamReader(new MemoryStream(), Encoding.UTF8, size, ArrayPool<byte>.Shared, ArrayPool<char>.Shared);
370var httpRequestStreamReader = new HttpRequestStreamReader(mockStream.Object, Encoding.UTF8, 1, ArrayPool<byte>.Shared, ArrayPool<char>.Shared);
378var httpRequestStreamReader = new HttpRequestStreamReader(new MemoryStream(), Encoding.UTF8, 10, ArrayPool<byte>.Shared, ArrayPool<char>.Shared);
391var httpRequestStreamReader = new HttpRequestStreamReader(new MemoryStream(), Encoding.UTF8, 10, ArrayPool<byte>.Shared, ArrayPool<char>.Shared);
400return new HttpRequestStreamReader(stream, Encoding.UTF8);
406return new HttpRequestStreamReader(stream, Encoding.UTF8, bufferSize);
441yield return new object?[] { null, Encoding.UTF8, ArrayPool<byte>.Shared, ArrayPool<char>.Shared };
443yield return new object?[] { new MemoryStream(), Encoding.UTF8, null, ArrayPool<char>.Shared };
444yield return new object?[] { new MemoryStream(), Encoding.UTF8, ArrayPool<byte>.Shared, null };
HttpResponseStreamWriterTest.cs (41)
38var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
54var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
73var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
94var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
111var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
130var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
149var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
168var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
189var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
214var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
238var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
260var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
293var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
317var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
341var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
364var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
383using var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
419var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
439var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
479var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
501var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
523var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
547var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
586var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
608var writer = new HttpResponseStreamWriter(stream, Encoding.UTF8);
628var encoding = Encoding.GetEncoding(encodingName);
662var encoding = Encoding.GetEncoding(encodingName);
686var encoding = Encoding.UTF8;
717var writer = new HttpResponseStreamWriter(stream, Encoding.Unicode);
725var streamReader = new StreamReader(stream, Encoding.Unicode);
732public static void NullInputsInConstructor_ExpectArgumentNullException(Stream stream, Encoding encoding, ArrayPool<byte> bytePool, ArrayPool<char> charPool)
747var httpRequestStreamReader = new HttpRequestStreamReader(new MemoryStream(), Encoding.UTF8, size, ArrayPool<byte>.Shared, ArrayPool<char>.Shared);
758var httpRequestStreamReader = new HttpRequestStreamReader(mockStream.Object, Encoding.UTF8, 1, ArrayPool<byte>.Shared, ArrayPool<char>.Shared);
766var httpResponseStreamWriter = new HttpResponseStreamWriter(new MemoryStream(), Encoding.UTF8, 10, ArrayPool<byte>.Shared, ArrayPool<char>.Shared);
779var httpResponseStreamWriter = new HttpResponseStreamWriter(new MemoryStream(), Encoding.UTF8, 10, ArrayPool<byte>.Shared, ArrayPool<char>.Shared);
848yield return new object?[] { null, Encoding.UTF8, ArrayPool<byte>.Shared, ArrayPool<char>.Shared };
850yield return new object?[] { new MemoryStream(), Encoding.UTF8, null, ArrayPool<char>.Shared };
851yield return new object?[] { new MemoryStream(), Encoding.UTF8, ArrayPool<byte>.Shared, null };
MultipartReaderTests.cs (21)
98return new MemoryStream(Encoding.UTF8.GetBytes(text));
103return Encoding.ASCII.GetString(buffer, 0, count);
118Assert.Equal("text default", Encoding.ASCII.GetString(buffer.ToArray()));
183Assert.Equal("text default", Encoding.ASCII.GetString(buffer.ToArray()));
198Assert.Equal("text default", Encoding.ASCII.GetString(buffer.ToArray()));
215Assert.Equal("text default", Encoding.ASCII.GetString(buffer.ToArray()));
232Assert.Equal("text default", Encoding.ASCII.GetString(buffer.ToArray()));
241Assert.Equal("Content of a.txt.\r\n", Encoding.ASCII.GetString(buffer.ToArray()));
258Assert.Equal("text default", Encoding.ASCII.GetString(buffer.ToArray()));
267Assert.Equal("Content of a.txt.\r\n", Encoding.ASCII.GetString(buffer.ToArray()));
284Assert.Equal("text default", Encoding.ASCII.GetString(buffer.ToArray()));
293Assert.Equal("Content of a.txt.\r\n", Encoding.ASCII.GetString(buffer.ToArray()));
302Assert.Equal("<!DOCTYPE html><title>Content of a.html.</title>\r\n", Encoding.ASCII.GetString(buffer.ToArray()));
345Assert.Equal("Content of a.txt.\r\n", Encoding.ASCII.GetString(buffer.ToArray()));
351Assert.Equal("<!DOCTYPE html><title>Content of a.html.</title>\r\n", Encoding.ASCII.GetString(buffer.ToArray()));
398var bytes = Encoding.UTF8.GetBytes(body1);
404bytes = Encoding.UTF8.GetBytes(body2);
415Assert.Equal("text default", Encoding.ASCII.GetString(buffer.ToArray()));
433var bytes = Encoding.UTF8.GetBytes(body1);
439bytes = Encoding.UTF8.GetBytes(body2);
450Assert.Equal("text default", Encoding.ASCII.GetString(buffer.ToArray()));
Microsoft.Build (46)
Microsoft.Build.CommandLine.UnitTests (2)
Microsoft.Build.Engine.OM.UnitTests (20)
Construction\ProjectRootElement_Tests.cs (11)
707Assert.Equal(Encoding.Unicode, project.Encoding);
713Assert.Equal(Encoding.UTF8, project.Encoding);
719Assert.Equal(Encoding.ASCII, project.Encoding);
732VerifyLoadedProjectHasEncoding(projectFullPath, Encoding.UTF8);
733VerifyLoadedProjectHasEncoding(projectFullPath, Encoding.Unicode);
767SaveProjectWithEncoding(projectFullPath, Encoding.Unicode);
768SaveProjectWithEncoding(projectFullPath, Encoding.ASCII);
769SaveProjectWithEncoding(projectFullPath, Encoding.UTF8);
1912private void SaveProjectWithEncoding(string projectFullPath, Encoding encoding)
1944private void VerifyLoadedProjectHasEncoding(string projectFullPath, Encoding encoding)
1957private void CreateProjectWithEncodingWithoutDeclaration(string projectFullPath, Encoding encoding)
Microsoft.Build.Engine.UnitTests (2)
Microsoft.Build.Framework (18)
Microsoft.Build.Tasks.CodeAnalysis (10)
Microsoft.Build.Tasks.Core (36)
Microsoft.Build.Tasks.UnitTests (7)
Microsoft.Build.UnitTests.Shared (5)
Microsoft.Build.Utilities.Core (9)
Microsoft.Build.Utilities.UnitTests (2)
Microsoft.CodeAnalysis (104)
EncodedStringText.cs (15)
20private static readonly Encoding s_utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
22private static readonly Lazy<Encoding> s_fallbackEncoding = new(CreateFallbackEncoding);
30internal static Encoding CreateFallbackEncoding()
38Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
43return Encoding.GetEncoding(0)
44?? Encoding.GetEncoding(1252);
48return Encoding.GetEncoding(name: "Latin1");
54/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
73Encoding? defaultEncoding = null,
85Lazy<Encoding> getEncoding,
86Encoding? defaultEncoding = null,
129Encoding encoding,
230internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
233internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
Text\LargeText.cs (6)
31private readonly Encoding? _encodingOpt;
33internal LargeText(ImmutableArray<char[]> chunks, Encoding? encodingOpt, ImmutableArray<byte> checksum, SourceHashAlgorithm checksumAlgorithm, ImmutableArray<byte> embeddedTextBlob)
50internal LargeText(ImmutableArray<char[]> chunks, Encoding? encodingOpt, SourceHashAlgorithm checksumAlgorithm)
55internal static SourceText Decode(Stream stream, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
81internal static SourceText Decode(TextReader reader, int length, Encoding? encodingOpt, SourceHashAlgorithm checksumAlgorithm)
152public override Encoding? Encoding => _encodingOpt;
Text\SourceText.cs (24)
48private static readonly Encoding s_utf8EncodingWithNoBOM = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: false);
98/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
105public static SourceText From(string text, Encoding? encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
124/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
134Encoding? encoding = null,
154public static SourceText From(Stream stream, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
163/// <see cref="Encoding.UTF8"/> if not specified.
182Encoding? encoding = null,
225public static SourceText From(byte[] buffer, int length, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
235/// <see cref="Encoding.UTF8"/> if not specified.
252Encoding? encoding = null,
290private static string Decode(Stream stream, Encoding encoding, out Encoding actualEncoding)
333private static string Decode(byte[] buffer, int length, Encoding encoding, out Encoding actualEncoding)
392/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
394public abstract Encoding? Encoding { get; }
424/// If this text was constructed via <see cref="From(byte[], int, Encoding, SourceHashAlgorithm, bool, bool)"/> or
425/// <see cref="From(Stream, Encoding, SourceHashAlgorithm, bool, bool)"/>, then the canBeEmbedded arg must have
1218internal static Encoding? TryReadByteOrderMark(byte[] source, int length, out int preambleLength)
1231return Encoding.BigEndianUnicode;
1240return Encoding.Unicode;
1249return Encoding.UTF8;
1289internal static int GetMaxCharCountOrThrowIfHuge(Encoding encoding, Stream stream)
Microsoft.CodeAnalysis.Analyzers (3)
Microsoft.CodeAnalysis.AnalyzerUtilities (3)
Microsoft.CodeAnalysis.BannedApiAnalyzers (3)
Microsoft.CodeAnalysis.CodeStyle (49)
src\Compilers\Core\Portable\EncodedStringText.cs (15)
20private static readonly Encoding s_utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
22private static readonly Lazy<Encoding> s_fallbackEncoding = new(CreateFallbackEncoding);
30internal static Encoding CreateFallbackEncoding()
38Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
43return Encoding.GetEncoding(0)
44?? Encoding.GetEncoding(1252);
48return Encoding.GetEncoding(name: "Latin1");
54/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
73Encoding? defaultEncoding = null,
85Lazy<Encoding> getEncoding,
86Encoding? defaultEncoding = null,
129Encoding encoding,
230internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
233internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Serialization\TextEncodingKind.cs (23)
34private static readonly Encoding s_encodingUtf8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
35private static readonly Encoding s_encodingUtf32_BE = new UTF32Encoding(bigEndian: true, byteOrderMark: false);
36private static readonly Encoding s_encodingUtf32_BE_BOM = new UTF32Encoding(bigEndian: true, byteOrderMark: true);
37private static readonly Encoding s_encodingUtf32_LE = new UTF32Encoding(bigEndian: false, byteOrderMark: false);
38private static readonly Encoding s_encodingUnicode_BE = new UnicodeEncoding(bigEndian: true, byteOrderMark: false);
39private static readonly Encoding s_encodingUnicode_LE = new UnicodeEncoding(bigEndian: false, byteOrderMark: false);
41public static Encoding GetEncoding(this TextEncodingKind kind)
45TextEncodingKind.EncodingUtf8_BOM => Encoding.UTF8,
49TextEncodingKind.EncodingUtf32_LE_BOM => Encoding.UTF32,
51TextEncodingKind.EncodingUnicode_BE_BOM => Encoding.BigEndianUnicode,
53TextEncodingKind.EncodingUnicode_LE_BOM => Encoding.Unicode,
57public static bool TryGetEncodingKind(this Encoding encoding, out TextEncodingKind kind)
62Debug.Assert(HasPreamble(Encoding.Unicode));
63kind = (encoding.Equals(Encoding.Unicode) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUnicode_LE_BOM : TextEncodingKind.EncodingUnicode_LE;
67Debug.Assert(HasPreamble(Encoding.BigEndianUnicode));
68kind = (encoding.Equals(Encoding.BigEndianUnicode) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUnicode_BE_BOM : TextEncodingKind.EncodingUnicode_BE;
72Debug.Assert(HasPreamble(Encoding.UTF32));
73kind = (encoding.Equals(Encoding.UTF32) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUtf32_LE_BOM : TextEncodingKind.EncodingUtf32_LE;
77Debug.Assert(HasPreamble(Encoding.UTF32));
78kind = (encoding.Equals(Encoding.UTF32) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUtf32_BE_BOM : TextEncodingKind.EncodingUtf32_BE;
82Debug.Assert(HasPreamble(Encoding.UTF8));
83kind = (encoding.Equals(Encoding.UTF8) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUtf8_BOM : TextEncodingKind.EncodingUtf8;
92public static bool HasPreamble(this Encoding encoding)
Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities (2)
Microsoft.CodeAnalysis.Compiler.Test.Resources (1)
Microsoft.CodeAnalysis.CSharp (23)
Syntax\CSharpSyntaxTree.cs (8)
314public static SyntaxTree Create(CSharpSyntaxNode root, CSharpParseOptions? options = null, string? path = "", Encoding? encoding = null)
334Encoding? encoding,
361Encoding? encoding,
393/// <para>NOTE: Do not use this method elsewhere, instead use <see cref="Create(CSharpSyntaxNode, CSharpParseOptions, string, Encoding)"/> method for creating a syntax tree.</para>
434Encoding? encoding = null,
455Encoding? encoding,
925Encoding? encoding,
937Encoding? encoding,
Syntax\SyntaxFactory.cs (6)
1547public static SyntaxTree SyntaxTree(SyntaxNode root, ParseOptions? options = null, string path = "", Encoding? encoding = null)
1554/// <inheritdoc cref="CSharpSyntaxTree.ParseText(string, CSharpParseOptions?, string, Encoding?, CancellationToken)"/>
1559Encoding? encoding = null,
1913return SourceText.From(text, Encoding.UTF8).GetSubText(offset);
2786Encoding? encoding,
2813Encoding? encoding,
Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests (11)
CommandLineTests.cs (10)
411Assert.Equal("星野 八郎太", File.ReadAllText(Path.Combine(dir.Path, "output.txt"), Encoding.GetEncoding(932)));
431Assert.Equal("星野 八郎太", File.ReadAllText(Path.Combine(dir.Path, "output.txt"), Encoding.GetEncoding(932)));
2307byte[] slContent = Encoding.UTF8.GetBytes(@"{ ""documents"" : {} }");
2525var sourceStr = Encoding.UTF8.GetString(sourceBlob.Array, sourceBlob.Offset, sourceBlob.Count);
2537private static void ValidateWrittenSources(Dictionary<string, Dictionary<string, string>> expectedFilesMap, Encoding encoding = null)
2544var content = File.ReadAllText(file, encoding ?? Encoding.UTF8);
7685var explicitManifestStream = new MemoryStream(Encoding.UTF8.GetBytes(explicitManifest));
9066return new TestStream(backingStream: new MemoryStream(Encoding.UTF8.GetBytes(@"
9254var actual = new string(Encoding.UTF8.GetChars(bytes));
14041context.AddSource("hint2", SourceText.From("class G2 { void F() {} }", Encoding.UTF8, checksumAlgorithm: SourceHashAlgorithm.Sha1));
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (42)
PdbSourceDocument\AbstractPdbSourceDocumentTests.cs (6)
196Encoding? encoding = null)
198var sourceText = SourceText.From(source, encoding: encoding ?? Encoding.UTF8);
211Encoding? fallbackEncoding = null)
248protected static void CompileTestSource(string path, SourceText source, Project project, Location pdbLocation, Location sourceLocation, bool buildReferenceAssembly, bool windowsPdb, Encoding? fallbackEncoding = null)
258protected static void CompileTestSource(string dllFilePath, string sourceCodePath, string? pdbFilePath, string assemblyName, SourceText source, Project project, Location pdbLocation, Location sourceLocation, bool buildReferenceAssembly, bool windowsPdb, Encoding? fallbackEncoding = null)
263protected static void CompileTestSource(string dllFilePath, string[] sourceCodePaths, string? pdbFilePath, string assemblyName, SourceText[] sources, Project project, Location pdbLocation, Location sourceLocation, bool buildReferenceAssembly, bool windowsPdb, Encoding? fallbackEncoding = null)
PdbSourceDocument\ImplementationAssemblyLookupServiceTests.cs (17)
43var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
81var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
123var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
161var sourceText = SourceText.From(metadataSource, Encoding.UTF8);
185sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
222var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
245sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
283var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
306sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
338var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
361sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
389var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
412sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
454var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
477sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
512var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
535var typeForwardSourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
PdbSourceDocument\PdbSourceDocumentLoaderServiceTests.cs (2)
48var result = await service.LoadSourceDocumentAsync(path, sourceDocument, Encoding.UTF8, new TelemetryMessage(CancellationToken.None), useExtendedTimeout: false, CancellationToken.None);
80var result = await service.LoadSourceDocumentAsync(path, sourceDocument, Encoding.UTF8, new TelemetryMessage(CancellationToken.None), useExtendedTimeout: false, CancellationToken.None);
PdbSourceDocument\PdbSourceDocumentTests.cs (16)
409var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
439var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
475var sourceText = SourceText.From(metadataSource, Encoding.UTF8);
522var sourceText = SourceText.From(metadataSource, Encoding.UTF8);
548sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
725CompileTestSource(path, SourceText.From(source2, Encoding.UTF8), project, Location.OnDisk, Location.OnDisk, buildReferenceAssembly: false, windowsPdb: false);
758File.WriteAllText(GetSourceFilePath(path), source2, Encoding.UTF8);
788var encoding = Encoding.GetEncoding(encodingWebName);
817var encoding = Encoding.GetEncoding("SJIS");
846var encoding = Encoding.GetEncoding("SJIS");
876var sourceText = SourceText.From(source, Encoding.UTF8);
927var sourceText1 = SourceText.From(source1, Encoding.UTF8);
928var sourceText2 = SourceText.From(source2, Encoding.UTF8);
Microsoft.CodeAnalysis.CSharp.Emit.UnitTests (6)
Microsoft.CodeAnalysis.CSharp.Emit2.UnitTests (18)
PDB\CSharpDeterministicBuildCompilationTests.cs (6)
109", filename: "a.cs", options: parseOptions, encoding: Encoding.UTF8);
119}", filename: "c.cs", options: parseOptions, encoding: Encoding.Unicode);
169", filename: "a.cs", options: parseOptions, encoding: Encoding.UTF8);
179}", filename: "a.cs", options: parseOptions, encoding: Encoding.Unicode);
233", filename: "a.cs", options: parseOptions, encoding: Encoding.UTF8);
243}", filename: "c.cs", options: parseOptions, encoding: Encoding.GetEncoding(932)); // SJIS encoding
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (23)
Attributes\AttributeTests_CallerInfoAttributes.cs (15)
4169SyntaxFactory.ParseSyntaxTree(source1, path: @"C:\filename", encoding: Encoding.UTF8),
4170SyntaxFactory.ParseSyntaxTree(source2, path: @"a\b\..\c\d", encoding: Encoding.UTF8),
4171SyntaxFactory.ParseSyntaxTree(source3, path: @"*", encoding: Encoding.UTF8),
4172SyntaxFactory.ParseSyntaxTree(source4, path: @" ", encoding: Encoding.UTF8),
4211SyntaxFactory.ParseSyntaxTree(source1, options: TestOptions.Regular9, path: @"C:\filename", encoding: Encoding.UTF8)
4264SyntaxFactory.ParseSyntaxTree(source1, path: @"C:\filename", encoding: Encoding.UTF8),
4265SyntaxFactory.ParseSyntaxTree(source2, path: @"a\b\..\c\d.cs", encoding: Encoding.UTF8),
4266SyntaxFactory.ParseSyntaxTree(source3, path: @"*", encoding: Encoding.UTF8),
4267SyntaxFactory.ParseSyntaxTree(source4, path: @"C:\x.cs", encoding: Encoding.UTF8),
4268SyntaxFactory.ParseSyntaxTree(source5, path: @"C:\x.cs", encoding: Encoding.UTF8),
5171new[] { SyntaxFactory.ParseSyntaxTree(source, path: @"C:\filename", encoding: Encoding.UTF8) },
5222new[] { SyntaxFactory.ParseSyntaxTree(source, options: TestOptions.Regular7, path: @"C:\filename", encoding: Encoding.UTF8) },
5555new[] { SyntaxFactory.ParseSyntaxTree(source, path: @"C:\filename", encoding: Encoding.UTF8) },
5615new[] { SyntaxFactory.ParseSyntaxTree(source, path: @"C:\filename", encoding: Encoding.UTF8) },
5670new[] { SyntaxFactory.ParseSyntaxTree(csSource, path: @"C:\filename", encoding: Encoding.UTF8) },
Attributes\AttributeTests_MarshalAs.cs (7)
757var arrayAqn = Encoding.ASCII.GetBytes("System.Int32*[][], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
758var openGenericAqn = Encoding.ASCII.GetBytes("System.Nullable`1, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
798var nestedAqn = Encoding.ASCII.GetBytes("C`1+D`1+E[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]");
830var e = Encoding.ASCII;
1039{ "CustomMarshaler6", new byte[] { 0x2c, 0x00, 0x00, 0x60 }.Append(Encoding.UTF8.GetBytes("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\0")) },
1041{ "CustomMarshaler8", new byte[] { 0x2c, 0x00, 0x00, 0x59 }.Append(Encoding.UTF8.GetBytes("System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\0")) },
Microsoft.CodeAnalysis.CSharp.Features (3)
Microsoft.CodeAnalysis.CSharp.Features.UnitTests (1)
Microsoft.CodeAnalysis.CSharp.Scripting.UnitTests (12)
ScriptTests.cs (12)
52var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2")), ScriptOptions);
148var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2")), ScriptOptions);
865var opts = ScriptOptions.WithEmitDebugInformation(true).WithFilePath("debug.csx").WithFileEncoding(Encoding.UTF8);
879var opts = ScriptOptions.WithEmitDebugInformation(false).WithFilePath("debug.csx").WithFileEncoding(Encoding.UTF8);
888return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), line: 1, column: 1, filename: "debug.csx");
895return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts));
910var opts = ScriptOptions.WithEmitDebugInformation(true).WithFileEncoding(Encoding.UTF8);
924var opts = ScriptOptions.WithEmitDebugInformation(false).WithFileEncoding(Encoding.UTF8);
933return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), line: 1, column: 1, filename: "");
940return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts));
1115System.Text.Encoding.ASCII.GetBytes(text, 0, text.Length, bytes, padding);
1128System.Text.Encoding.ASCII,
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (36)
SourceGeneration\AdditionalSourcesCollectionTests.cs (20)
54asc.Add(hintName, SourceText.From("public class D{}", Encoding.UTF8));
70asc.Add(hintName, SourceText.From("public class D{}", Encoding.UTF8));
110var exception = Assert.Throws<ArgumentException>(nameof(hintName), () => asc.Add(hintName, SourceText.From("public class D{}", Encoding.UTF8)));
120asc.Add("file3.cs", SourceText.From("", Encoding.UTF8));
121asc.Add("file1.cs", SourceText.From("", Encoding.UTF8));
122asc.Add("file2.cs", SourceText.From("", Encoding.UTF8));
123asc.Add("file5.cs", SourceText.From("", Encoding.UTF8));
124asc.Add("file4.cs", SourceText.From("", Encoding.UTF8));
144asc.Add(names[i], SourceText.From("", Encoding.UTF8));
166asc.Add(hintName1, SourceText.From("", Encoding.UTF8));
167var exception = Assert.Throws<ArgumentException>("hintName", () => asc.Add(hintName2, SourceText.From("", Encoding.UTF8)));
176asc.Add("hintName1", SourceText.From("", Encoding.UTF8));
177asc.Add("hintName2", SourceText.From("", Encoding.UTF8));
180asc2.Add("hintName3", SourceText.From("", Encoding.UTF8));
181asc2.Add("hintName1", SourceText.From("", Encoding.UTF8));
200asc.Add(addHintName, SourceText.From("", Encoding.UTF8));
212asc.Add(addHintName, SourceText.From("", Encoding.UTF8));
224asc.Add("file1.cs", SourceText.From("", Encoding.UTF8));
225asc.Add("file2.cs", SourceText.From("", Encoding.UTF32));
226asc.Add("file3.cs", SourceText.From("", Encoding.Unicode));
SourceGeneration\GeneratorDriverTests.cs (11)
460sgc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8));
463Assert.Throws<ArgumentException>("hintName", () => sgc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8)));
466Assert.Throws<ArgumentException>("hintName", () => sgc.AddSource("test.cs", SourceText.From("public class D{}", Encoding.UTF8)));
491spc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8));
494Assert.Throws<ArgumentException>("hintName", () => spc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8)));
497Assert.Throws<ArgumentException>("hintName", () => spc.AddSource("test.cs", SourceText.From("public class D{}", Encoding.UTF8)));
504spc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8));
586var generator = new CallbackGenerator((ic) => { }, (sgc) => { sgc.AddSource("test", SourceText.From("public class D {}", Encoding.UTF8)); });
616var generator = new CallbackGenerator((ic) => { }, (sgc) => { sgc.AddSource("test", SourceText.From("public class D {}", Encoding.UTF8)); sgc.AddSource("test2", SourceText.From("public class E {}", Encoding.UTF8)); });
756e.AddSource("a", SourceText.From("public class E {}", Encoding.UTF8));
Microsoft.CodeAnalysis.CSharp.Symbol.UnitTests (19)
Symbols\Source\FileModifierTests.cs (14)
730var verifier = CompileAndVerify(SyntaxFactory.ParseSyntaxTree(source, options: TestOptions.RegularPreview, path: "path/to/MyFile.cs", encoding: Encoding.Default), expectedOutput: "1", symbolValidator: symbolValidator);
773var verifier = CompileAndVerify(SyntaxFactory.ParseSyntaxTree(source, options: TestOptions.RegularPreview, path: "path/to/My<>File.cs", encoding: Encoding.Default), expectedOutput: "1", symbolValidator: symbolValidator);
804var verifier = CompileAndVerify(SyntaxFactory.ParseSyntaxTree(source, options: TestOptions.RegularPreview, path: "path/to/MyGeneratedFile.g.cs", encoding: Encoding.Default), expectedOutput: "1", symbolValidator: symbolValidator);
874""", options: TestOptions.RegularPreview, path: path, encoding: Encoding.Default);
875var source2 = SyntaxFactory.ParseSyntaxTree("", options: TestOptions.RegularPreview, path: path, encoding: Encoding.Default);
909""", options: TestOptions.RegularPreview, path: path, encoding: Encoding.Default);
919""", options: TestOptions.RegularPreview, path: path, encoding: Encoding.Default);
956""", options: TestOptions.RegularPreview, path: path, encoding: Encoding.Default);
957var source2 = SyntaxFactory.ParseSyntaxTree("", options: TestOptions.RegularPreview, path: path, encoding: Encoding.Default);
990""", options: TestOptions.RegularPreview, path: "path/to/file.cs", encoding: Encoding.Default);
991var source2 = SyntaxFactory.ParseSyntaxTree("", options: TestOptions.RegularPreview, path: "path/to/File.cs", encoding: Encoding.Default);
1086var comp = CreateCompilation(SyntaxFactory.ParseSyntaxTree(source, options: TestOptions.RegularPreview, path: $"path/to/My{badChar}File.cs", encoding: Encoding.Default));
1148var verifier = CompileAndVerify(SyntaxFactory.ParseSyntaxTree(source, options: TestOptions.RegularPreview, path: "path/to/My+File.cs", encoding: Encoding.Default), expectedOutput: "1", symbolValidator: validateSymbols);
4588encoding: Encoding.Default);
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (9)
Syntax\SyntaxTreeTests.cs (7)
86SyntaxTreeFactoryKind.ParseText => CSharpSyntaxTree.ParseText(SourceText.From(source, Encoding.UTF8, SourceHashAlgorithm.Sha256), parseOptions),
87SyntaxTreeFactoryKind.Subclass => new MockCSharpSyntaxTree(root, SourceText.From(source, Encoding.UTF8, SourceHashAlgorithm.Sha256), parseOptions),
89SyntaxTreeFactoryKind.ParsedTreeWithPath => WithInitializedDirectives(CSharpSyntaxTree.Create(root, options: parseOptions, path: "old path", Encoding.UTF8)).WithFilePath("new path"),
259var oldText = SourceText.From("class B {}", Encoding.Unicode, SourceHashAlgorithms.Default);
269Assert.Same(Encoding.Unicode, newText.Encoding);
301var oldText = SourceText.From("class B {}", Encoding.Unicode, SourceHashAlgorithms.Default);
310Assert.Same(Encoding.Unicode, newText.Encoding);
Microsoft.CodeAnalysis.CSharp.Test.Utilities (4)
Microsoft.CodeAnalysis.CSharp.WinRT.UnitTests (2)
Microsoft.CodeAnalysis.CSharp.Workspaces (3)
Microsoft.CodeAnalysis.Debugging.Package (1)
Microsoft.CodeAnalysis.EditorFeatures (6)
Workspaces\EditorTextFactoryService.cs (6)
30private static readonly Encoding s_throwingUtf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
32public SourceText CreateText(Stream stream, Encoding? defaultEncoding, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
50defaultEncoding = Encoding.Default;
65public SourceText CreateText(TextReader reader, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
77private SourceText CreateTextInternal(Stream stream, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
85return buffer.CurrentSnapshot.AsRoslynText(_textBufferCloneService, reader.CurrentEncoding ?? Encoding.UTF8, checksumAlgorithm);
Microsoft.CodeAnalysis.EditorFeatures.Text (9)
Extensions.SnapshotSourceText.cs (5)
34private readonly Encoding? _encoding;
37private SnapshotSourceText(ITextBufferCloneService? textBufferCloneService, ITextSnapshot editorSnapshot, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, TextBufferContainer container)
48public SnapshotSourceText(ITextBufferCloneService? textBufferCloneService, ITextImage textImage, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, TextBufferContainer? container)
105public override Encoding? Encoding
266public ClosedSnapshotSourceText(ITextBufferCloneService? textBufferCloneService, ITextImage textImage, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm)
Microsoft.CodeAnalysis.EditorFeatures.UnitTests (14)
Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler (4)
Microsoft.CodeAnalysis.ExpressionEvaluator.ResultProvider (2)
Microsoft.CodeAnalysis.ExpressionEvaluator.ResultProvider.Utilities (2)
Microsoft.CodeAnalysis.Features (20)
PdbSourceDocument\PdbSourceDocumentLoaderService.cs (5)
37public async Task<SourceFileInfo?> LoadSourceDocumentAsync(string tempFilePath, SourceDocument sourceDocument, Encoding encoding, TelemetryMessage telemetry, bool useExtendedTimeout, CancellationToken cancellationToken)
46private SourceFileInfo? TryGetEmbeddedSourceFile(string tempFilePath, SourceDocument sourceDocument, Encoding encoding, TelemetryMessage telemetry)
124private async Task<SourceFileInfo?> TryGetSourceLinkFileAsync(SourceDocument sourceDocument, Encoding encoding, TelemetryMessage telemetry, bool useExtendedTimeout, CancellationToken cancellationToken)
168private SourceFileInfo? TryGetOriginalFile(SourceDocument sourceDocument, Encoding encoding, TelemetryMessage telemetry)
189private static SourceFileInfo? LoadSourceFile(string filePath, SourceDocument sourceDocument, Encoding encoding, string sourceDescription, bool ignoreChecksum, bool fromRemoteLocation)
Microsoft.CodeAnalysis.Features.Test.Utilities (11)
Microsoft.CodeAnalysis.Features.UnitTests (52)
EditAndContinue\EditAndContinueWorkspaceServiceTests.cs (41)
42Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
44var encodingA = Encoding.BigEndianUnicode;
45var encodingB = Encoding.Unicode;
46var encodingC = Encoding.GetEncoding("SJIS");
47var encodingE = Encoding.UTF8;
59var sourceBytesD1 = Encoding.UTF8.GetBytesWithPreamble(sourceD1);
394var sourceFilePath = dir.CreateFile(sourceFileName).WriteAllText(source, Encoding.UTF8).Path;
413solution = solution.AddDocument(designTimeOnlyDocumentId, designTimeOnlyFileName, SourceText.From(sourceDesignTimeOnly, Encoding.UTF8), filePath: designTimeOnlyFilePath);
433solution = solution.AddDocument(designTimeOnlyDocumentId, designTimeOnlyFileName, SourceText.From(sourceDesignTimeOnly, Encoding.UTF8), filePath: designTimeOnlyFilePath);
571var sourceFile = dir.CreateFile("a.cs").WriteAllText(source1, Encoding.UTF8);
622var sourceFile = dir.CreateFile("a.cs").WriteAllText(source1, Encoding.UTF8);
628AddDocument("a.cs", SourceText.From(source1, Encoding.UTF8, SourceHashAlgorithm.Sha1), filePath: sourceFile.Path);
678var sourceFileA = Temp.CreateFile().WriteAllText(sourceA, Encoding.UTF8);
679var sourceFileB = Temp.CreateFile().WriteAllText(sourceB, Encoding.UTF8);
777sourceFile.WriteAllText(source1, Encoding.UTF8);
908Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
912var encoding = Encoding.GetEncoding(1252);
1155sourceFile.WriteAllText(source1, Encoding.UTF8);
1188sourceFile.WriteAllText(source0, Encoding.UTF8);
1251var sourceFile = dir.CreateFile("a.cs").WriteAllText(source1, Encoding.UTF8);
1294var sourceFile = dir.CreateFile("a.cs").WriteAllText(source1, Encoding.UTF8);
1411File.WriteAllText(sourceFilePath, source3, Encoding.UTF8);
1811context.AddSource("generated.cs", SourceText.From("generated: " + additionalText, Encoding.UTF8, SourceHashAlgorithm.Sha256));
1883var sourceFileA = dir.CreateFile("a.cs").WriteAllText(sourceA1, Encoding.UTF8);
1884var sourceFileB = dir.CreateFile("b.cs").WriteAllText(sourceB1, Encoding.UTF8);
2221var sourceFile = dir.CreateFile("test.cs").WriteAllText(source1, Encoding.UTF8);
2259sourceFile.WriteAllText(source2, Encoding.UTF8);
2308var sourceFile = dir.CreateFile("test.cs").WriteAllText(source2, Encoding.UTF8);
2355sourceFile.WriteAllText(source1, Encoding.UTF8);
2380var sourceFile = dir.CreateFile("test.cs").WriteAllText(source1, Encoding.UTF8);
2441var sourceFile = dir.CreateFile("test.cs").WriteAllText(sourceOnDisk, Encoding.UTF8);
3570var sourcePath = dir.CreateFile("Lib.cs").WriteAllText(source1, Encoding.UTF8).Path;
3630File.WriteAllText(sourcePath, source2, Encoding.UTF8);
3667var sourcePath = dir.CreateFile("Lib.cs").WriteAllText(source1, Encoding.UTF8).Path;
4741var sourceFileA = dir.CreateFile("A.cs").WriteAllText(source1, Encoding.UTF8);
4755loader: new WorkspaceFileTextLoader(solution.Services, sourceFileA.Path, Encoding.UTF8),
Microsoft.CodeAnalysis.InteractiveHost (4)
Microsoft.CodeAnalysis.LanguageServer (1)
Microsoft.CodeAnalysis.LanguageServer.Protocol (2)
Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests (3)
Workspaces\LspWorkspaceManagerTests.cs (3)
88await testLspServer.TestWorkspace.ChangeDocumentAsync(firstDocument.Id, SourceText.From($"Some more text{markupOne}", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default));
122await testLspServer.TestWorkspace.ChangeDocumentAsync(secondDocument.Id, SourceText.From("Two is now three!", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default));
224var newSolution = testLspServer.TestWorkspace.CurrentSolution.AddDocument(newDocumentId, "NewDoc.cs", SourceText.From("New Doc", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default), filePath: @"C:\NewDoc.cs");
Microsoft.CodeAnalysis.PublicApiAnalyzers (3)
Microsoft.CodeAnalysis.Rebuild (6)
Microsoft.CodeAnalysis.Rebuild.UnitTests (8)
Microsoft.CodeAnalysis.Remote.ServiceHub (1)
Microsoft.CodeAnalysis.Remote.Workspaces (12)
Microsoft.CodeAnalysis.ResxSourceGenerator (7)
Microsoft.CodeAnalysis.ResxSourceGenerator.UnitTests (4)
Microsoft.CodeAnalysis.Scripting (3)
Microsoft.CodeAnalysis.Scripting.TestUtilities (4)
Microsoft.CodeAnalysis.Scripting.UnitTests (4)
Microsoft.CodeAnalysis.Test.Utilities (35)
Microsoft.CodeAnalysis.TestAnalyzerReference (3)
Microsoft.CodeAnalysis.UnitTests (104)
EmbeddedTextTests.cs (20)
42Assert.Throws<ArgumentException>("text", () => EmbeddedText.FromSource("path", SourceText.From(new byte[0], 0, Encoding.UTF8, canBeEmbedded: false)));
43Assert.Throws<ArgumentException>("text", () => EmbeddedText.FromSource("path", SourceText.From(new MemoryStream(new byte[0]), Encoding.UTF8, canBeEmbedded: false)));
116var bytes = Encoding.UTF8.GetBytes(SmallSource);
130var bytes = Encoding.UTF8.GetBytes(SmallSource);
145var source = SourceText.From(SmallSource, Encoding.UTF8, SourceHashAlgorithm.Sha1);
152AssertEx.Equal(Encoding.UTF8.GetPreamble().Concat(Encoding.UTF8.GetBytes(SmallSource)), text.Blob.Skip(4));
158var bytes = Encoding.Unicode.GetBytes(LargeSource);
172var bytes = Encoding.Unicode.GetBytes(LargeSource);
187var source = SourceText.From(LargeSource, Encoding.Unicode, SourceHashAlgorithms.Default);
193AssertEx.Equal(BitConverter.GetBytes(Encoding.Unicode.GetPreamble().Length + LargeSource.Length * sizeof(char)), text.Blob.Take(4));
194AssertEx.Equal(Encoding.Unicode.GetPreamble().Concat(Encoding.Unicode.GetBytes(LargeSource)), Decompress(text.Blob.Skip(4)));
200var expected = SourceText.From(SmallSource, Encoding.UTF8, SourceHashAlgorithm.Sha1);
203var actual = SourceText.From(new StringReader(SmallSource), SmallSource.Length, Encoding.UTF8, SourceHashAlgorithm.Sha1);
215var expected = SourceText.From(LargeSource, Encoding.UTF8, SourceHashAlgorithm.Sha1);
218var actual = SourceText.From(new StringReader(LargeSource), LargeSource.Length, Encoding.UTF8, SourceHashAlgorithm.Sha1);
230byte[] bytes = Encoding.ASCII.GetBytes(LargeSource);
236SourceText.From(new MemoryStream(bytes), Encoding.ASCII, SourceHashAlgorithm.Sha1, canBeEmbedded: true) :
237SourceText.From(bytes, bytes.Length, Encoding.ASCII, SourceHashAlgorithm.Sha1, canBeEmbedded: true);
Text\LargeTextTests.cs (7)
18private static SourceText CreateSourceText(string s, Encoding encoding = null)
22using (StreamWriter sw = new StreamWriter(stream, encoding ?? Encoding.UTF8, bufferSize: 1024, leaveOpen: true))
31private static SourceText CreateSourceText(Stream stream, Encoding encoding = null)
33return LargeText.Decode(stream, encoding ?? Encoding.UTF8, SourceHashAlgorithm.Sha1, throwIfBinaryDetected: true, canBeEmbedded: false);
36private static SourceText CreateSourceText(TextReader reader, int length, Encoding encoding = null)
38return LargeText.Decode(reader, length, encoding ?? Encoding.UTF8, SourceHashAlgorithm.Sha1);
115using (StreamWriter sw = new StreamWriter(stream, Encoding.UTF8, bufferSize: 1024, leaveOpen: true))
Text\SourceTextTests.cs (22)
22private static readonly Encoding s_utf8 = Encoding.UTF8;
23private static readonly Encoding s_unicode = Encoding.Unicode;
201private static SourceText FromLargeTextWriter(string source, Encoding encoding, SourceHashAlgorithm checksumAlgorithm)
251var encodings = new[] { null, Encoding.ASCII, new UTF8Encoding(encoderShouldEmitUTF8Identifier: true), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false) };
258foreach (var encoding in encodings)
282var encodings = new[] { null, Encoding.ASCII, new UTF8Encoding(encoderShouldEmitUTF8Identifier: true), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false) };
284foreach (var encoding1 in encodings)
288foreach (var encoding2 in encodings)
296if (encoding1 == Encoding.ASCII && encoding2 == Encoding.ASCII)
305var sourceText1 = new StringText(";", Encoding.ASCII); // chinese semicolon
306var sourceText2 = new StringText("?", Encoding.ASCII); // what a non-ascii char will map to.
332var encoding = Encoding.UTF8;
384private static void TestTryReadByteOrderMark(Encoding expectedEncoding, int expectedPreambleLength, byte[] data)
389private static void TestTryReadByteOrderMark(Encoding expectedEncoding, int expectedPreambleLength, byte[] data, int validLength)
392Encoding actualEncoding = SourceText.TryReadByteOrderMark(data, validLength, out actualPreambleLength);
412TestTryReadByteOrderMark(expectedEncoding: Encoding.UTF8, expectedPreambleLength: 3, data: new byte[] { 0xef, 0xBB, 0xBF });
415TestTryReadByteOrderMark(expectedEncoding: Encoding.Unicode, expectedPreambleLength: 2, data: new byte[] { 0xff, 0xfe });
418TestTryReadByteOrderMark(expectedEncoding: Encoding.BigEndianUnicode, expectedPreambleLength: 2, data: new byte[] { 0xfe, 0xff });
Text\StringTextDecodingTests.cs (27)
19private static SourceText CreateMemoryStreamBasedEncodedText(string text, Encoding writeEncoding, Encoding readEncodingOpt, SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
26private static SourceText CreateMemoryStreamBasedEncodedText(byte[] bytes, Encoding readEncodingOpt, SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
40Func<Encoding> getEncoding,
41Encoding readEncodingOpt = null,
51return EncodedStringText.TestAccessor.Create(stream, new Lazy<Encoding>(getEncoding), readEncodingOpt, algorithm, canBeEmbedded: false);
58var sjis = Encoding.GetEncoding(932);
68var sjis = Encoding.GetEncoding(932);
78var data = CreateMemoryStreamBasedEncodedText("The quick brown fox jumps over the lazy dog", Encoding.ASCII, readEncodingOpt: null);
88var data = CreateMemoryStreamBasedEncodedText("The quick brown fox jumps over the lazy dog", Encoding.Unicode, readEncodingOpt: null);
97var data = CreateMemoryStreamBasedEncodedText("The quick brown fox jumps over the lazy dog", Encoding.BigEndianUnicode, readEncodingOpt: null);
106var data = CreateMemoryStreamBasedEncodedText("", Encoding.ASCII, readEncodingOpt: null);
116var data = CreateMemoryStreamBasedEncodedText("", Encoding.Unicode, readEncodingOpt: null);
125var data = CreateMemoryStreamBasedEncodedText("", Encoding.BigEndianUnicode, readEncodingOpt: null);
134var data = CreateMemoryStreamBasedEncodedText("", Encoding.UTF8, readEncodingOpt: null, algorithm: SourceHashAlgorithm.Sha256);
197Assert.Equal(Encoding.UTF8.EncodingName, sourceText.Encoding.EncodingName);
234var encodings = new Encoding[]
240foreach (var writeEncoding in encodings)
242foreach (var readEncoding in encodings)
254var writeEncodings = new Encoding[]
261var readEncodings = new Encoding[]
270foreach (var writeEncoding in writeEncodings)
272foreach (var readEncoding in readEncodings)
295var encodings = new Encoding[]
302foreach (var encoding in encodings)
Text\StringTextTest.cs (11)
46var data = SourceText.From("goo", Encoding.UTF8);
69Assert.Throws<ArgumentNullException>(() => SourceText.From((string)null, Encoding.UTF8));
75Assert.Throws<ArgumentNullException>(() => SourceText.From((Stream)null, Encoding.UTF8));
76Assert.Throws<ArgumentException>(() => SourceText.From(new TestStream(canRead: false, canSeek: true), Encoding.UTF8));
77Assert.Throws<NotImplementedException>(() => SourceText.From(new TestStream(canRead: true, canSeek: false), Encoding.UTF8));
83var data = SourceText.From(string.Empty, Encoding.UTF8);
224var data = SourceText.From("The quick brown fox jumps over the lazy dog", Encoding.UTF8);
234var source = SourceText.From(new MemoryStream(bytes), Encoding.ASCII);
249var source = SourceText.From(new MemoryStream(bytes), Encoding.ASCII);
259var bytes = Encoding.UTF8.GetBytes("\u1234");
276var source = SourceText.From(stream, Encoding.ASCII);
Text\TextChangeTests.cs (5)
189var text = SourceText.From("Hello World", Encoding.Unicode, SourceHashAlgorithms.Default);
198Assert.Same(Encoding.Unicode, subText.Encoding);
231var text = SourceText.From(new string('.', 2048), Encoding.Unicode, SourceHashAlgorithms.Default); // start bigger than GetText() copy buffer
241Assert.Same(Encoding.Unicode, newText.Encoding);
590return new LargeText(ImmutableArray.Create(chunks), Encoding.UTF8, default(ImmutableArray<byte>), SourceHashAlgorithms.Default, default(ImmutableArray<byte>));
Microsoft.CodeAnalysis.VisualBasic (19)
Microsoft.CodeAnalysis.VisualBasic.CommandLine.UnitTests (4)
Microsoft.CodeAnalysis.VisualBasic.Emit.UnitTests (23)
Attributes\AttributeTests_MarshalAs.vb (6)
605Dim aqn = Encoding.ASCII.GetBytes("System.Int32[][], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
606Dim openGenericAqn = Encoding.ASCII.GetBytes("System.Nullable`1, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
652Dim nestedAqn = Encoding.ASCII.GetBytes("C`1+D`1+E[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")
685Dim e = Encoding.ASCII
891{"CustomMarshaler6", New Byte() {&H2C, &H0, &H0, &H60}.Append(Encoding.UTF8.GetBytes("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" & ChrW(0)))},
893{"CustomMarshaler8", New Byte() {&H2C, &H0, &H0, &H59}.Append(Encoding.UTF8.GetBytes("System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" & ChrW(0)))},
Microsoft.CodeAnalysis.VisualBasic.Features.UnitTests (1)
Microsoft.CodeAnalysis.VisualBasic.Semantic.UnitTests (9)
Semantics\OptionalArgumentTests.vb (9)
2023SyntaxFactory.ParseSyntaxTree(source1, path:="C:\filename", encoding:=Encoding.UTF8),
2024SyntaxFactory.ParseSyntaxTree(source2, path:="a\b\..\c\d", encoding:=Encoding.UTF8),
2025SyntaxFactory.ParseSyntaxTree(source3, path:="*", encoding:=Encoding.UTF8),
2026SyntaxFactory.ParseSyntaxTree(source4, path:=" ", encoding:=Encoding.UTF8)
2103SyntaxFactory.ParseSyntaxTree(source1, path:="C:\filename", encoding:=Encoding.UTF8),
2104SyntaxFactory.ParseSyntaxTree(source2, path:="a\b\..\c\d.vb", encoding:=Encoding.UTF8),
2105SyntaxFactory.ParseSyntaxTree(source3, path:="*", encoding:=Encoding.UTF8),
2106SyntaxFactory.ParseSyntaxTree(source4, path:="C:\x.vb", encoding:=Encoding.UTF8),
2107SyntaxFactory.ParseSyntaxTree(source5, path:="C:\x.vb", encoding:=Encoding.UTF8)
Microsoft.CodeAnalysis.VisualBasic.Syntax.UnitTests (6)
Microsoft.CodeAnalysis.VisualBasic.Test.Utilities (8)
Microsoft.CodeAnalysis.VisualBasic.Workspaces (3)
Microsoft.CodeAnalysis.Workspaces (80)
src\Compilers\Core\Portable\EncodedStringText.cs (15)
20private static readonly Encoding s_utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
22private static readonly Lazy<Encoding> s_fallbackEncoding = new(CreateFallbackEncoding);
30internal static Encoding CreateFallbackEncoding()
38Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
43return Encoding.GetEncoding(0)
44?? Encoding.GetEncoding(1252);
48return Encoding.GetEncoding(name: "Latin1");
54/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
73Encoding? defaultEncoding = null,
85Lazy<Encoding> getEncoding,
86Encoding? defaultEncoding = null,
129Encoding encoding,
230internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
233internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Serialization\TextEncodingKind.cs (23)
34private static readonly Encoding s_encodingUtf8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
35private static readonly Encoding s_encodingUtf32_BE = new UTF32Encoding(bigEndian: true, byteOrderMark: false);
36private static readonly Encoding s_encodingUtf32_BE_BOM = new UTF32Encoding(bigEndian: true, byteOrderMark: true);
37private static readonly Encoding s_encodingUtf32_LE = new UTF32Encoding(bigEndian: false, byteOrderMark: false);
38private static readonly Encoding s_encodingUnicode_BE = new UnicodeEncoding(bigEndian: true, byteOrderMark: false);
39private static readonly Encoding s_encodingUnicode_LE = new UnicodeEncoding(bigEndian: false, byteOrderMark: false);
41public static Encoding GetEncoding(this TextEncodingKind kind)
45TextEncodingKind.EncodingUtf8_BOM => Encoding.UTF8,
49TextEncodingKind.EncodingUtf32_LE_BOM => Encoding.UTF32,
51TextEncodingKind.EncodingUnicode_BE_BOM => Encoding.BigEndianUnicode,
53TextEncodingKind.EncodingUnicode_LE_BOM => Encoding.Unicode,
57public static bool TryGetEncodingKind(this Encoding encoding, out TextEncodingKind kind)
62Debug.Assert(HasPreamble(Encoding.Unicode));
63kind = (encoding.Equals(Encoding.Unicode) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUnicode_LE_BOM : TextEncodingKind.EncodingUnicode_LE;
67Debug.Assert(HasPreamble(Encoding.BigEndianUnicode));
68kind = (encoding.Equals(Encoding.BigEndianUnicode) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUnicode_BE_BOM : TextEncodingKind.EncodingUnicode_BE;
72Debug.Assert(HasPreamble(Encoding.UTF32));
73kind = (encoding.Equals(Encoding.UTF32) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUtf32_LE_BOM : TextEncodingKind.EncodingUtf32_LE;
77Debug.Assert(HasPreamble(Encoding.UTF32));
78kind = (encoding.Equals(Encoding.UTF32) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUtf32_BE_BOM : TextEncodingKind.EncodingUtf32_BE;
82Debug.Assert(HasPreamble(Encoding.UTF8));
83kind = (encoding.Equals(Encoding.UTF8) || HasPreamble(encoding)) ? TextEncodingKind.EncodingUtf8_BOM : TextEncodingKind.EncodingUtf8;
92public static bool HasPreamble(this Encoding encoding)
Microsoft.CodeAnalysis.Workspaces.MSBuild (7)
Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost (4)
Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests (3)
Microsoft.CodeAnalysis.Workspaces.Test.Utilities (1)
Microsoft.CodeAnalysis.Workspaces.UnitTests (59)
SolutionTests\SolutionTests.cs (42)
58.AddDocument(DocumentId.CreateNewId(projectId), "goo.cs", SourceText.From("public class Goo { }", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "goo.cs"))
59.AddAdditionalDocument(DocumentId.CreateNewId(projectId), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default))
60.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), "editorcfg", SourceText.From(editorConfig ?? "#empty", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "editorcfg"))));
80.AddDocument(DocumentId.CreateNewId(projectId1), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
81.AddAdditionalDocument(DocumentId.CreateNewId(projectId1), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "add.txt")
82.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId1), "editorcfg", SourceText.From("config", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "/a/b")
84.AddDocument(DocumentId.CreateNewId(projectId2), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
85.AddAdditionalDocument(DocumentId.CreateNewId(projectId2), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "add.txt")
86.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId2), "editorcfg", SourceText.From("config", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "/a/b")));
841.AddDocument(DocumentId.CreateNewId(projectId1), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
843.AddDocument(DocumentId.CreateNewId(projectId2), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")));
1091.AddDocument(d1, "d1.cs", SourceText.From("class D1;", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "d1.cs"))
1092.AddDocument(d2, "d2.cs", SourceText.From("class D2;", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "d2.cs"))
1093.AddAdditionalDocument(a1, "a1.txt", SourceText.From("text1", Encoding.UTF8, SourceHashAlgorithms.Default))
1094.AddAdditionalDocument(a2, "a2.txt", SourceText.From("text2", Encoding.UTF8, SourceHashAlgorithms.Default))
1095.AddAnalyzerConfigDocument(c1, "c1", SourceText.From("#empty1", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "editorcfg"))
1096.AddAnalyzerConfigDocument(c2, "c2", SourceText.From("#empty2", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "editorcfg"));
1106loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class NewD1;", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1115loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class NewD3;", Encoding.UTF8, SourceHashAlgorithms.Default), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD3.cs"))),
1125loader: TextLoader.From(TextAndVersion.Create(SourceText.From("new text1", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1134loader: TextLoader.From(TextAndVersion.Create(SourceText.From("new text3", Encoding.UTF8, SourceHashAlgorithms.Default), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD3.cs"))),
1144loader: TextLoader.From(TextAndVersion.Create(SourceText.From("#new empty1", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1153loader: TextLoader.From(TextAndVersion.Create(SourceText.From("#new empty3", Encoding.UTF8, SourceHashAlgorithms.Default), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD3.cs"))),
1235Assert.Same(Encoding.UTF32, newText1.Encoding);
1244Assert.Same(Encoding.UTF8, newText3.Encoding);
1256Assert.Same(Encoding.UTF32, newAddText1.Encoding);
1265Assert.Same(Encoding.UTF8, newAddText3.Encoding);
1277Assert.Same(Encoding.UTF32, newConfigText1.Encoding);
1286Assert.Same(Encoding.UTF8, newConfigText3.Encoding);
3292var file = Temp.CreateFile().WriteAllText(text1, Encoding.UTF8);
3302.AddDocument(did, "x", new WorkspaceFileTextLoader(workspace.Services.SolutionServices, file.Path, Encoding.UTF8));
3346var file = Temp.CreateFile().WriteAllText(text, Encoding.UTF8);
3351.AddDocument(did, "x", new WorkspaceFileTextLoader(workspace.Services.SolutionServices, file.Path, Encoding.UTF8));
3413var file = Temp.CreateFile().WriteAllText(text, Encoding.UTF8);
3418.AddDocument(did, "x", new WorkspaceFileTextLoader(workspace.Services.SolutionServices, file.Path, Encoding.UTF8));
3774.AddDocument(did, "test", SourceText.From(language == LanguageNames.CSharp ? "class C {}" : "Class C : End Class", Encoding.UTF8, SourceHashAlgorithm.Sha256), filePath: "old path");
3913.AddDocument(did, "x", new WorkspaceFileTextLoader(solution.Services, @"C:\doesnotexist.cs", Encoding.UTF8))
3999var doc = ws.AddDocument(proj.Id, "a.cs", SourceText.From("public class c { }", Encoding.UTF32));
4001Assert.Equal(Encoding.UTF32, doc.GetTextAsync().Result.Encoding);
4008Assert.Equal(Encoding.UTF32, newDoc.GetTextAsync().Result.Encoding);
4508public TestSmallFileTextLoader(string path, Encoding encoding)
4523var loader = new TestSmallFileTextLoader(file.Path, Encoding.UTF8);
Microsoft.Data.Analysis (25)
DataFrame.IO.cs (10)
110bool addIndexColumn = false, Encoding encoding = null,
490private readonly Encoding _encoding;
493public WrappedStreamReaderOrStringReader(Stream stream, Encoding encoding)
571Encoding encoding = null, bool renameDuplicatedColumns = false, CultureInfo cultureInfo = null,
584WrappedStreamReaderOrStringReader wrappedStreamReaderOrStringReader = new WrappedStreamReaderOrStringReader(csvStream, encoding ?? Encoding.UTF8);
600Encoding encoding = null, CultureInfo cultureInfo = null)
616Encoding encoding = null, CultureInfo cultureInfo = null)
638Encoding encoding = null, CultureInfo cultureInfo = null)
654Encoding encoding = null, CultureInfo cultureInfo = null)
668encoding = Encoding.ASCII;
TextFieldParser.cs (9)
355InitializeFromPath(path, Encoding.ASCII, detectEncoding: true);
358public TextFieldParser(string path, Encoding defaultEncoding)
363public TextFieldParser(string path, Encoding defaultEncoding, bool detectEncoding)
370InitializeFromStream(stream, Encoding.ASCII, detectEncoding: true);
373public TextFieldParser(Stream stream, Encoding defaultEncoding)
378public TextFieldParser(Stream stream, Encoding defaultEncoding, bool detectEncoding)
383public TextFieldParser(Stream stream, Encoding defaultEncoding, bool detectEncoding, bool leaveOpen)
549private void InitializeFromPath(string path, Encoding defaultEncoding, bool detectEncoding)
565private void InitializeFromStream(Stream stream, Encoding defaultEncoding, bool detectEncoding)
Microsoft.Data.Analysis.Tests (13)
src\Microsoft.Data.Analysis\TextFieldParser.cs (9)
355InitializeFromPath(path, Encoding.ASCII, detectEncoding: true);
358public TextFieldParser(string path, Encoding defaultEncoding)
363public TextFieldParser(string path, Encoding defaultEncoding, bool detectEncoding)
370InitializeFromStream(stream, Encoding.ASCII, detectEncoding: true);
373public TextFieldParser(Stream stream, Encoding defaultEncoding)
378public TextFieldParser(Stream stream, Encoding defaultEncoding, bool detectEncoding)
383public TextFieldParser(Stream stream, Encoding defaultEncoding, bool detectEncoding, bool leaveOpen)
549private void InitializeFromPath(string path, Encoding defaultEncoding, bool detectEncoding)
565private void InitializeFromStream(Stream stream, Encoding defaultEncoding, bool detectEncoding)
Microsoft.DotNet.Arcade.Sdk (6)
Microsoft.DotNet.AsmDiff (4)
Microsoft.DotNet.Build.Tasks.Feed (9)
Microsoft.DotNet.Build.Tasks.Installers (41)
src\ArWriter.cs (7)
32Write(Encoding.ASCII.GetBytes(entry.Name.PadRight(16, ' ').Substring(0, 16)));
33Write(Encoding.ASCII.GetBytes(entry.Timestamp.ToString().PadRight(12, ' ').Substring(0, 12)));
34Write(Encoding.ASCII.GetBytes(entry.OwnerID.ToString().PadRight(6, ' ').Substring(0, 6)));
35Write(Encoding.ASCII.GetBytes(entry.GroupID.ToString().PadRight(6, ' ').Substring(0, 6)));
36Write(Encoding.ASCII.GetBytes(Convert.ToString(entry.Mode, 8).PadRight(8, ' ').Substring(0, 8)));
40Write(Encoding.ASCII.GetBytes(length.ToString().PadRight(10, ' ').Substring(0, 10)));
41Write(Encoding.ASCII.GetBytes("`\n"));
src\CpioReader.cs (14)
36ulong inode = ulong.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
39uint mode = uint.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
42ulong ownerID = ulong.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
45ulong groupID = ulong.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
48ushort numberOfLinks = ushort.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
51ulong timestamp = ulong.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
54ulong size = ulong.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
57ulong devMajor = ulong.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
60ulong devMinor = ulong.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
63ulong rdevMajor = ulong.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
66ulong rdevMinor = ulong.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
69int namesize = int.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
73_ = int.Parse(Encoding.ASCII.GetString(byteBuffer), NumberStyles.HexNumber);
77string name = Encoding.ASCII.GetString(nameBuffer, 0, namesize - 1);
Microsoft.DotNet.Build.Tasks.Packaging (2)
Microsoft.DotNet.Build.Tasks.VisualStudio (8)
Microsoft.DotNet.Build.Tasks.Workloads (6)
Microsoft.DotNet.Deployment.Tasks.Links (1)
Microsoft.DotNet.Git.IssueManager (1)
Microsoft.DotNet.Helix.Client (7)
Microsoft.DotNet.Helix.JobSender (5)
Microsoft.DotNet.Helix.Sdk (5)
Microsoft.DotNet.Internal.SymbolHelper (2)
Microsoft.DotNet.Open.Api.Tools.Tests (3)
Microsoft.DotNet.SignCheckLibrary (2)
Microsoft.DotNet.SignTool.Tests (4)
Microsoft.DotNet.SwaggerGenerator.CodeGenerator (1)
Microsoft.DotNet.XliffTasks (3)
Microsoft.Extensions.AI (2)
Microsoft.Extensions.AI.Abstractions (1)
Microsoft.Extensions.AI.Abstractions.Tests (1)
Microsoft.Extensions.AI.Evaluation.Reporting (1)
Microsoft.Extensions.AI.Evaluation.Reporting.Tests (2)
Microsoft.Extensions.AI.Integration.Tests (4)
Microsoft.Extensions.AI.OpenAI (4)
Microsoft.Extensions.ApiDescription.Tool.Tests (2)
Microsoft.Extensions.Caching.Abstractions (4)
Microsoft.Extensions.Caching.Hybrid (2)
Microsoft.Extensions.Caching.Hybrid.Tests (1)
Microsoft.Extensions.Caching.SqlServer.Tests (20)
SqlServerCacheWithDatabaseTest.cs (20)
77var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
99var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
126var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
166var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
208var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
235Encoding.UTF8.GetBytes("Hello, World!"),
259var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
291var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
318Encoding.UTF8.GetBytes("Hello, World!"),
341Encoding.UTF8.GetBytes("Hello, World!"),
364var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
393var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
420var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
489var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
521var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
577var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
606var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
636Encoding.UTF8.GetBytes("Hello, World!"),
653var expectedValue = Encoding.UTF8.GetBytes("Hello, World!");
676Encoding.UTF8.GetBytes("Hello, World!"),
Microsoft.Extensions.Caching.StackExchangeRedis (1)
Microsoft.Extensions.Caching.StackExchangeRedis.Tests (1)
Microsoft.Extensions.Configuration.KeyPerFile.Tests (1)
Microsoft.Extensions.Diagnostics.ResourceMonitoring (5)
Linux\OSFileSystem.cs (5)
41return Encoding.ASCII.GetChars(rentedBuffer.Span.Slice(0, read), destination);
75_ = Encoding.ASCII.GetChars(buffer.Span.Slice(start, length), destination.GetSpan(length));
90_ = Encoding.ASCII.GetChars(buffer.Span.Slice(start, length), destination.GetSpan(length));
131_ = Encoding.ASCII.GetChars(buffer.Slice(0, end), destination.GetSpan(end));
138_ = Encoding.ASCII.GetChars(buffer.Slice(0, end), destination.GetSpan(end));
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests (3)
Microsoft.Extensions.FileProviders.Embedded.Tests (1)
Microsoft.Extensions.FileProviders.Physical (3)
Microsoft.Extensions.Hosting.Systemd (2)
Microsoft.Extensions.Http.Diagnostics (2)
Microsoft.Extensions.Http.Diagnostics.Tests (49)
Logging\HttpClientLoggerTest.cs (19)
87Content = new StringContent(input, Encoding.UTF8, TextPlain)
125Content = new StringContent(input, Encoding.UTF8, TextPlain)
187Content = new StringContent(requestContent, Encoding.UTF8, TextPlain)
196Content = new StringContent(responseContent, Encoding.UTF8, TextPlain),
283Content = new StringContent(requestContent, Encoding.UTF8, TextPlain)
290Content = new StringContent(responseContent, Encoding.UTF8, TextPlain),
388Content = new StringContent(requestContent, Encoding.UTF8, TextPlain)
396Content = new StringContent(responseContent, Encoding.UTF8, TextPlain),
484Content = new StringContent(requestContent, Encoding.UTF8, TextPlain)
492Content = new StringContent(responseContent, Encoding.UTF8, TextPlain),
599Content = new StringContent(requestContent, Encoding.UTF8, TextPlain)
606Content = new StringContent(responseContent, Encoding.UTF8, TextPlain),
691Content = new StringContent(_fixture.Create<string>(), Encoding.UTF8, TextPlain)
734Content = new StringContent(_fixture.Create<string>(), Encoding.UTF8, TextPlain)
772Content = new StringContent(_fixture.Create<string>(), Encoding.UTF8, TextPlain)
816Content = new StringContent(_fixture.Create<string>(), Encoding.UTF8, TextPlain)
859using var requestContent = new StreamContent(new NotSeekableStream(new(Encoding.UTF8.GetBytes(requestInput))));
870using var responseContent = new StreamContent(new NotSeekableStream(new(Encoding.UTF8.GetBytes(responseInput))));
961Content = new StringContent("request_content", Encoding.UTF8, TextPlain)
Logging\HttpRequestBodyReaderTest.cs (6)
41Content = new StringContent(input, Encoding.UTF8, "text/plain"),
85Content = new StringContent(input, Encoding.UTF8, contentType),
106Content = new StringContent(input, Encoding.UTF8, "text/plain"),
134Content = new StringContent(input, Encoding.UTF8, "text/plain"),
158Content = new StringContent(input, Encoding.UTF8, "text/plain"),
232Content = new StringContent("content", Encoding.UTF8, "text/plain"),
Logging\HttpRequestReaderTest.cs (15)
84Content = new StringContent(requestContent, Encoding.UTF8)
93Content = new StringContent(responseContent, Encoding.UTF8)
147Content = new StringContent(requestContent, Encoding.UTF8)
153Content = new StringContent(responseContent, Encoding.UTF8)
210Content = new StringContent(requestContent, Encoding.UTF8),
222Content = new StringContent(responseContent, Encoding.UTF8)
285Content = new StringContent(requestContent, Encoding.UTF8),
297Content = new StringContent(responseContent, Encoding.UTF8)
357Content = new StringContent(requestContent, Encoding.UTF8),
415Content = new StringContent(requestContent, Encoding.UTF8),
427Content = new StringContent(responseContent, Encoding.UTF8)
486Content = new StringContent(requestContent, Encoding.UTF8),
494Content = new StringContent(responseContent, Encoding.UTF8)
553Content = new StringContent(requestContent, Encoding.UTF8),
562Content = new StringContent(responseContent, Encoding.UTF8)
Microsoft.Extensions.Http.Resilience.Tests (1)
Microsoft.Extensions.Identity.Core (2)
Microsoft.Extensions.Logging.Console (2)
Microsoft.Extensions.Logging.EventSource (1)
Microsoft.Extensions.Logging.Generators (1)
Microsoft.Extensions.Options.SourceGeneration (1)
Microsoft.Extensions.SecretManager.Tools.Tests (7)
Microsoft.Extensions.Telemetry.Tests (2)
Microsoft.Gen.ComplianceReports (1)
Microsoft.Gen.Logging (1)
Microsoft.Gen.MetadataExtractor (3)
Microsoft.Gen.Metrics (2)
Microsoft.Gen.MetricsReports (1)
Microsoft.JSInterop (3)
Microsoft.JSInterop.Tests (8)
Microsoft.Maui (2)
Microsoft.Maui.Controls (1)
Microsoft.Maui.Controls.SourceGen (4)
Microsoft.Maui.Graphics (3)
Microsoft.ML.AutoML.SourceGenerator (3)
Microsoft.ML.AutoML.Tests (1)
Microsoft.ML.Core (12)
Microsoft.ML.Data (10)
Microsoft.ML.FastTree (4)
Microsoft.ML.OnnxConverter (4)
Microsoft.ML.OnnxTransformer (1)
Microsoft.ML.PerformanceTests (1)
Microsoft.ML.Samples (1)
Microsoft.ML.Samples.GPU (1)
Microsoft.ML.TestFramework (2)
Microsoft.ML.TestFrameworkCommon (2)
Microsoft.ML.Tokenizers (37)
SentencepieceModel.cs (5)
1399private readonly static string UnkPieceDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("PHVuaz4="), 0, 5);
1425private readonly static string BosPieceDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("PHM+"), 0, 3);
1451private readonly static string EosPieceDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("PC9zPg=="), 0, 4);
1477private readonly static string PadPieceDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("PHBhZD4="), 0, 5);
1503private readonly static string UnkSurfaceDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("IOKBhyA="), 0, 5);
Microsoft.ML.Tokenizers.Tests (14)
src\Microsoft.ML.Tokenizers\Utils\Helpers.netstandard.cs (5)
76return Encoding.UTF8.GetBytes(sourcePtr, source.Length, destPtr, destination.Length);
85if (Encoding.UTF8.GetByteCount(sourcePtr, source.Length) <= destination.Length)
87bytesWritten = Encoding.UTF8.GetBytes(sourcePtr, source.Length, destPtr, destination.Length);
100return Encoding.UTF8.GetString(sourcePtr, utf8Bytes.Length);
109return Encoding.UTF8.GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length);
Microsoft.Net.Http.Headers (12)
Microsoft.VisualBasic.Core (16)
Microsoft\VisualBasic\FileIO\FileSystem.vb (8)
300Return OpenTextFileReader(file, Encoding.UTF8)
309Public Shared Function OpenTextFileReader(ByVal file As String, ByVal encoding As Encoding) As IO.StreamReader
322Return OpenTextFileWriter(file, append, Encoding.UTF8)
333ByVal encoding As Encoding) As IO.StreamWriter
367Public Shared Function ReadAllText(ByVal file As String, ByVal encoding As Encoding) As String
773WriteAllText(file, text, append, Encoding.UTF8)
786ByVal encoding As Encoding)
2156Friend Sub New(ByVal Encoding As Text.Encoding, ByVal Text As String, ByVal IgnoreCase As Boolean)
Microsoft.VisualBasic.Forms (10)
Microsoft.VisualBasic.Forms.Tests (8)
Microsoft.VisualStudio.LanguageServices (6)
Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests (3)
Microsoft.VisualStudio.LanguageServices.LiveShare (1)
MSBuild (11)
MSBuildTaskHost (6)
mscorlib (1)
netstandard (1)
PlaintextApp (1)
PresentationBuildTasks (3)
PresentationCore (4)
PresentationFramework (22)
System\Windows\Documents\XamlToRtfWriter.cs (3)
3896Encoding e = null;
3928private static void AppendRtfChar(StringBuilder sb, char c, int cp, ref Encoding e, byte[] rgAnsi, char[] rgChar)
4011private static void AppendRtfUnicodeChar(StringBuilder sb, char c, int cp, ref Encoding e, byte[] rgAnsi, char[] rgChar)
PresentationUI (1)
RazorBuildWebSite (1)
ReachFramework (7)
Replay (6)
Roslyn.Diagnostics.Analyzers (3)
Roslyn.Test.PdbUtilities (5)
Roslyn.VisualStudio.Next.UnitTests (13)
Services\ServiceHubServicesTests.cs (9)
513private static SourceText CreateText(string content, Encoding encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
514=> SourceText.From(content, encoding ?? Encoding.UTF8, checksumAlgorithm);
602[("SG.cs", CreateText("X", Encoding.ASCII))],
603[("SG.cs", CreateText("X", Encoding.UTF8))]);
610[("SG.cs", CreateText("X", Encoding.UTF8, checksumAlgorithm: SourceHashAlgorithm.Sha1))],
611[("SG.cs", CreateText("X", Encoding.UTF8, checksumAlgorithm: SourceHashAlgorithm.Sha256))]);
737return ImmutableArray.Create(("hint", SourceText.From($"// generated document {callCount}", Encoding.UTF8)));
821return ImmutableArray.Create(("hint", SourceText.From($"// generated document {callCount}", Encoding.UTF8)));
876return ImmutableArray.Create(("hint", SourceText.From($"// generated document {callCount}", Encoding.UTF8)));
RoutingSandbox (4)
RoutingWebSite (3)
Security.TransportSecurity.IntegrationTests (8)
Https\HttpsTests.4.1.0.cs (6)
82CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8), new HttpsTransportBindingElement());
160CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8), new HttpsTransportBindingElement());
199CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressing10, Encoding.UTF8), new HttpsTransportBindingElement());
240CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8), new HttpsTransportBindingElement());
286CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8), new HttpsTransportBindingElement());
327CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8), new HttpsTransportBindingElement());
SecurityWebSite (1)
SemanticSearch.BuildTask (2)
ServiceBusWorker (1)
Shared (4)
SignalRSamples (3)
SocialWeather (6)
Sockets.BindTests (4)
Sockets.FunctionalTests (16)
Stress.ApiService (1)
System.CodeDom (7)
System.ComponentModel.TypeConverter (2)
System.Configuration.ConfigurationManager (8)
System.Console (32)
System.Data.Common (5)
System.Data.Odbc (10)
System.Diagnostics.Process (14)
System.Drawing.Common.Tests (17)
System\Drawing\ImageTests.cs (17)
48Assert.Equal("LEAD Technologies Inc. V1.01\0", Encoding.ASCII.GetString(items[0].Value));
105Assert.Equal("LEAD Technologies Inc. V1.01\0", Encoding.ASCII.GetString(item.Value));
246Assert.Equal("Hello World\0", Encoding.ASCII.GetString(items[0].Value));
261Assert.Equal("Hello World\0", Encoding.ASCII.GetString(items[0].Value));
265Assert.Equal("New Value\0", Encoding.ASCII.GetString(items[1].Value));
276Assert.Equal("Hello World\0", Encoding.ASCII.GetString(items[0].Value));
280Assert.Equal("New Value\0", Encoding.ASCII.GetString(items[1].Value));
304Assert.Equal("Hello World\0", Encoding.ASCII.GetString(items[0].Value));
347Assert.Equal("Hello World\0", Encoding.ASCII.GetString(items[0].Value));
379Assert.Equal("New Value\0", Encoding.ASCII.GetString(items[3].Value));
390Assert.Equal("Hello World\0", Encoding.ASCII.GetString(items[0].Value));
422Assert.Equal("New Value\0", Encoding.ASCII.GetString(items[3].Value));
447Assert.Equal("Hello World\0", Encoding.ASCII.GetString(items[0].Value));
462Assert.Equal("Hello World\0", Encoding.ASCII.GetString(items[0].Value));
466Assert.Equal("New Value\0", Encoding.ASCII.GetString(items[1].Value));
477Assert.Equal("Hello World\0", Encoding.ASCII.GetString(items[0].Value));
481Assert.Equal("New Value\0", Encoding.ASCII.GetString(items[1].Value));
System.Formats.Asn1 (12)
System.Formats.Cbor (15)
System.Formats.Tar (19)
System.IO.Compression (17)
System\IO\Compression\ZipArchive.cs (8)
32private Encoding? _entryNameAndCommentEncoding;
121public ZipArchive(Stream stream, ZipArchiveMode mode, bool leaveOpen, Encoding? entryNameEncoding)
181private ZipArchive(ZipArchiveMode mode, bool leaveOpen, Encoding? entryNameEncoding, Stream? backingStream, Stream archiveStream)
205/// The comment encoding is determined by the <c>entryNameEncoding</c> parameter of the <see cref="ZipArchive(Stream,ZipArchiveMode,bool,Encoding?)"/> constructor.
211get => (EntryNameAndCommentEncoding ?? Encoding.UTF8).GetString(_archiveComment);
346internal Encoding? EntryNameAndCommentEncoding
368(value.Equals(Encoding.BigEndianUnicode)
369|| value.Equals(Encoding.Unicode)))
System.IO.Compression.ZipFile (18)
System\IO\Compression\ZipFile.Create.Async.cs (5)
152public static async Task<ZipArchive> OpenAsync(string archiveFileName, ZipArchiveMode mode, Encoding? entryNameEncoding, CancellationToken cancellationToken = default)
335CompressionLevel compressionLevel, bool includeBaseDirectory, Encoding? entryNameEncoding, CancellationToken cancellationToken = default) =>
422CompressionLevel compressionLevel, bool includeBaseDirectory, Encoding? entryNameEncoding, CancellationToken cancellationToken = default) =>
426CompressionLevel? compressionLevel, bool includeBaseDirectory, Encoding? entryNameEncoding, CancellationToken cancellationToken)
445CompressionLevel? compressionLevel, bool includeBaseDirectory, Encoding? entryNameEncoding, CancellationToken cancellationToken)
System\IO\Compression\ZipFile.Create.cs (5)
144public static ZipArchive Open(string archiveFileName, ZipArchiveMode mode, Encoding? entryNameEncoding)
319CompressionLevel compressionLevel, bool includeBaseDirectory, Encoding? entryNameEncoding) =>
400CompressionLevel compressionLevel, bool includeBaseDirectory, Encoding? entryNameEncoding) =>
404CompressionLevel? compressionLevel, bool includeBaseDirectory, Encoding? entryNameEncoding)
418CompressionLevel? compressionLevel, bool includeBaseDirectory, Encoding? entryNameEncoding)
System\IO\Compression\ZipFile.Extract.Async.cs (4)
134public static Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, Encoding? entryNameEncoding, CancellationToken cancellationToken = default) =>
191public static async Task ExtractToDirectoryAsync(string sourceArchiveFileName, string destinationDirectoryName, Encoding? entryNameEncoding, bool overwriteFiles, CancellationToken cancellationToken = default)
301public static Task ExtractToDirectoryAsync(Stream source, string destinationDirectoryName, Encoding? entryNameEncoding, CancellationToken cancellationToken = default) =>
341public static async Task ExtractToDirectoryAsync(Stream source, string destinationDirectoryName, Encoding? entryNameEncoding, bool overwriteFiles, CancellationToken cancellationToken = default)
System\IO\Compression\ZipFile.Extract.cs (4)
126public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName, Encoding? entryNameEncoding) =>
181public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName, Encoding? entryNameEncoding, bool overwriteFiles)
282public static void ExtractToDirectory(Stream source, string destinationDirectoryName, Encoding? entryNameEncoding) =>
320public static void ExtractToDirectory(Stream source, string destinationDirectoryName, Encoding? entryNameEncoding, bool overwriteFiles)
System.IO.FileSystem.Watcher (1)
System.IO.MemoryMappedFiles (2)
System.IO.Packaging (3)
System.IO.Ports (5)
System.Memory (24)
System\Text\EncodingExtensions.cs (24)
26/// Encodes the specified <see cref="ReadOnlySpan{Char}"/> to <see langword="byte"/>s using the specified <see cref="Encoding"/>
29/// <param name="encoding">The <see cref="Encoding"/> which represents how the data in <paramref name="chars"/> should be encoded.</param>
34public static long GetBytes(this Encoding encoding, ReadOnlySpan<char> chars, IBufferWriter<byte> writer)
61/// Decodes the specified <see cref="ReadOnlySequence{Char}"/> to <see langword="byte"/>s using the specified <see cref="Encoding"/>
64/// <param name="encoding">The <see cref="Encoding"/> which represents how the data in <paramref name="chars"/> should be encoded.</param>
70public static long GetBytes(this Encoding encoding, in ReadOnlySequence<char> chars, IBufferWriter<byte> writer)
90/// Encodes the specified <see cref="ReadOnlySequence{Char}"/> to <see langword="byte"/>s using the specified <see cref="Encoding"/>
93/// <param name="encoding">The <see cref="Encoding"/> which represents how the data in <paramref name="chars"/> should be encoded.</param>
100public static int GetBytes(this Encoding encoding, in ReadOnlySequence<char> chars, Span<byte> bytes)
135/// Encodes the specified <see cref="ReadOnlySequence{Char}"/> into a <see cref="byte"/> array using the specified <see cref="Encoding"/>.
137/// <param name="encoding">The <see cref="Encoding"/> which represents how the data in <paramref name="chars"/> should be encoded.</param>
142public static byte[] GetBytes(this Encoding encoding, in ReadOnlySequence<char> chars)
216/// Decodes the specified <see cref="ReadOnlySpan{Byte}"/> to <see langword="char"/>s using the specified <see cref="Encoding"/>
219/// <param name="encoding">The <see cref="Encoding"/> which represents how the data in <paramref name="bytes"/> should be decoded.</param>
225public static long GetChars(this Encoding encoding, ReadOnlySpan<byte> bytes, IBufferWriter<char> writer)
252/// Decodes the specified <see cref="ReadOnlySequence{Byte}"/> to <see langword="char"/>s using the specified <see cref="Encoding"/>
255/// <param name="encoding">The <see cref="Encoding"/> which represents how the data in <paramref name="bytes"/> should be decoded.</param>
261public static long GetChars(this Encoding encoding, in ReadOnlySequence<byte> bytes, IBufferWriter<char> writer)
281/// Decodes the specified <see cref="ReadOnlySequence{Byte}"/> to <see langword="char"/>s using the specified <see cref="Encoding"/>
284/// <param name="encoding">The <see cref="Encoding"/> which represents how the data in <paramref name="bytes"/> is encoded.</param>
291public static int GetChars(this Encoding encoding, in ReadOnlySequence<byte> bytes, Span<char> chars)
326/// Decodes the specified <see cref="ReadOnlySequence{Byte}"/> into a <see cref="string"/> using the specified <see cref="Encoding"/>.
328/// <param name="encoding">The <see cref="Encoding"/> which represents how the data in <paramref name="bytes"/> is encoded.</param>
333public static string GetString(this Encoding encoding, in ReadOnlySequence<byte> bytes)
System.Memory.Data (2)
System.Net.Http (119)
src\libraries\Common\src\System\Net\Http\aspnetcore\Http2\Hpack\HPackEncoder.cs (12)
77public static bool EncodeLiteralHeaderFieldWithoutIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
109public static bool EncodeLiteralHeaderFieldNeverIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
141public static bool EncodeLiteralHeaderFieldIndexing(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
208public static bool EncodeLiteralHeaderFieldIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
229public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
250public static bool EncodeLiteralHeaderFieldNeverIndexingNewName(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
270private static bool EncodeLiteralHeaderNewNameCore(byte mask, string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
288public static bool EncodeLiteralHeaderFieldWithoutIndexingNewName(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
449public static bool EncodeStringLiteral(string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
464int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
513public static bool EncodeStringLiterals(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
533if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
src\libraries\Common\src\System\Net\Http\aspnetcore\Http3\QPack\QPackEncoder.cs (9)
66public static bool EncodeLiteralHeaderFieldWithStaticNameReference(int index, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
89/// Encodes just the name part of a Literal Header Field With Static Name Reference. Must call <see cref="EncodeValueString(string, Encoding?, Span{byte}, out int)"/> after to encode the header's value.
130public static bool EncodeLiteralHeaderFieldWithoutNameReference(string name, string value, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
147public static bool EncodeLiteralHeaderFieldWithoutNameReference(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding, Span<byte> destination, out int bytesWritten)
160/// Encodes just the value part of a Literawl Header Field Without Static Name Reference. Must call <see cref="EncodeValueString(string, Encoding?, Span{byte}, out int)"/> after to encode the header's value.
182private static bool EncodeValueString(string s, Encoding? valueEncoding, Span<byte> buffer, out int length)
188int encodedStringLength = valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1)
220public static bool EncodeValueString(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, Span<byte> buffer, out int length)
239if (valueEncoding is null || ReferenceEquals(valueEncoding, Encoding.Latin1))
System\Net\Http\HttpContent.cs (16)
25internal static readonly Encoding DefaultStringEncoding = Encoding.UTF8;
41AssertEncodingConstants(Encoding.UTF8, UTF8CodePage, UTF8Preamble);
44AssertEncodingConstants(Encoding.UTF32, UTF32CodePage, UTF32Preamble);
46AssertEncodingConstants(Encoding.Unicode, UnicodeCodePage, UnicodePreamble);
48AssertEncodingConstants(Encoding.BigEndianUnicode, BigEndianUnicodeCodePage, BigEndianUnicodePreamble);
51private static void AssertEncodingConstants(Encoding encoding, int codePage, ReadOnlySpan<byte> preamble)
118Encoding? encoding = null;
134encoding = Encoding.GetEncoding(charset.Substring(1, charset.Length - 2));
138encoding = Encoding.GetEncoding(charset);
699private static int GetPreambleLength(ReadOnlySpan<byte> data, Encoding encoding)
723private static bool TryDetectEncoding(ReadOnlySpan<byte> data, [NotNullWhen(true)] out Encoding? encoding, out int preambleLength)
727encoding = Encoding.UTF8;
734encoding = Encoding.UTF32;
741encoding = Encoding.Unicode;
748encoding = Encoding.BigEndianUnicode;
System\Net\Http\SocketsHttpHandler\Http2Connection.cs (9)
444string response = Encoding.ASCII.GetString(_incomingBuffer.ActiveSpan.Slice(0, Math.Min(20, _incomingBuffer.ActiveLength)));
770string altSvcHeaderValue = Encoding.ASCII.GetString(span);
1376private void WriteLiteralHeader(string name, ReadOnlySpan<string> values, Encoding? valueEncoding, ref ArrayBuffer headerBuffer)
1389private void WriteLiteralHeaderValues(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding, ref ArrayBuffer headerBuffer)
1391if (NetEventSource.Log.IsEnabled()) Trace($"{nameof(values)}={string.Join(Encoding.ASCII.GetString(separator ?? []), values.ToArray())}");
1402private void WriteLiteralHeaderValue(string value, Encoding? valueEncoding, ref ArrayBuffer headerBuffer)
1441Encoding? valueEncoding = encodingSelector?.Invoke(header.Key.Name, request);
1537Encoding? protocolEncoding = _pool.Settings._requestHeaderEncodingSelector?.Invoke(":protocol", request);
1552Encoding? cookieEncoding = _pool.Settings._requestHeaderEncodingSelector?.Invoke(KnownHeaders.Cookie.Name, request);
System\Net\Http\SocketsHttpHandler\Http3RequestStream.cs (9)
675Encoding? valueEncoding = _connection.Pool.Settings._requestHeaderEncodingSelector?.Invoke(HttpKnownHeaderNames.Cookie, request);
734Encoding? valueEncoding = encodingSelector?.Invoke(header.Key.Name, _request);
791private void BufferLiteralHeaderWithStaticNameReference(int nameIndex, string value, Encoding? valueEncoding = null)
801private void BufferLiteralHeaderWithoutNameReference(string name, ReadOnlySpan<string> values, byte[] separator, Encoding? valueEncoding)
811private void BufferLiteralHeaderWithoutNameReference(string name, string value, Encoding? valueEncoding)
821private void BufferLiteralHeaderValues(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding)
957throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.Format(SR.net_http_invalid_response_header_name, Encoding.ASCII.GetString(name)));
1039return HttpConnectionBase.ParseStatusCode(Encoding.ASCII.GetBytes(value));
1089Encoding? encoding = _connection.Pool.Settings._responseHeaderEncodingSelector?.Invoke(descriptor.Name, _request);
System\Net\Http\SocketsHttpHandler\HttpConnection.cs (10)
439Encoding? valueEncoding = encodingSelector?.Invoke(header.Key.Name, _currentRequest);
502private void WriteString(string s, Encoding? encoding)
1065throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.Format(SR.net_http_invalid_response_status_line, Encoding.ASCII.GetString(line)));
1086throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.Format(SR.net_http_invalid_response_status_line, Encoding.ASCII.GetString(line)));
1094throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.Format(SR.net_http_invalid_response_status_code, Encoding.ASCII.GetString(line.Slice(9, 3))));
1119throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.Format(SR.net_http_invalid_response_status_reason, Encoding.ASCII.GetString(reasonBytes.ToArray())), formatEx);
1125throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.Format(SR.net_http_invalid_response_status_line, Encoding.ASCII.GetString(line)));
1224throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.Format(SR.net_http_invalid_response_header_line, Encoding.ASCII.GetString(buffer.Slice(0, newLineIndex))));
1276Encoding? valueEncoding = _pool.Settings._responseHeaderEncodingSelector?.Invoke(descriptor.Name, _currentRequest!);
1326throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.Format(SR.net_http_invalid_response_header_name, Encoding.ASCII.GetString(name)));
System.Net.Http.Json (17)
System.Net.HttpListener (24)
System.Net.Mail (82)
System\Net\Mail\MailAddress.cs (13)
20private readonly Encoding _displayNameEncoding;
27internal MailAddress(string displayName, string userName, string domain, Encoding? displayNameEncoding)
32_displayNameEncoding = displayNameEncoding ?? Encoding.GetEncoding(MimeBasePart.DefaultCharSet);
44public MailAddress(string address) : this(address, null, (Encoding?)null)
48public MailAddress(string address, string? displayName) : this(address, displayName, (Encoding?)null)
65public MailAddress(string address, string? displayName, Encoding? displayNameEncoding)
68out (string displayName, string user, string host, Encoding displayNameEncoding) parsedData,
101/// <param name="displayNameEncoding">The <see cref="Encoding"/> that defines the character set used for displayName</param>
104public static bool TryCreate([NotNullWhen(true)] string? address, string? displayName, Encoding? displayNameEncoding, [NotNullWhen(true)] out MailAddress? result)
107out (string displayName, string user, string host, Encoding displayNameEncoding) parsed,
120private static bool TryParse([NotNullWhen(true)] string? address, string? displayName, Encoding? displayNameEncoding, out (string displayName, string user, string host, Encoding displayNameEncoding) parsedData, bool throwExceptionIfFail)
132displayNameEncoding ??= Encoding.GetEncoding(MimeBasePart.DefaultCharSet);
System.Net.Ping (2)
System.Net.Primitives (2)
System.Net.Requests (5)
System.Net.Security (19)
src\libraries\Common\src\Microsoft\Win32\SafeHandles\GssSafeHandles.cs (3)
22out minorStatus, name, Encoding.UTF8.GetByteCount(name), out retHandle);
39out minorStatus, name, Encoding.UTF8.GetByteCount(name), out retHandle);
120status = Interop.NetSecurityNative.InitiateCredWithPassword(out minorStatus, packageType, userHandle, password, Encoding.UTF8.GetByteCount(password), out retHandle);
System.Net.ServerSentEvents (4)
System.Net.Sockets (3)
System.Net.WebClient (13)
System.Net.WebHeaderCollection (1)
System.Net.WebSockets (2)
System.Net.WebSockets.Client (3)
System.Private.CoreLib (289)
src\libraries\System.Private.CoreLib\src\System\Globalization\NumberFormatInfo.cs (15)
273Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_currencyDecimalSeparatorUtf8 ??= Encoding.UTF8.GetBytes(_currencyDecimalSeparator));
365Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_currencyGroupSeparatorUtf8 ??= Encoding.UTF8.GetBytes(_currencyGroupSeparator));
387Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_currencySymbolUtf8 ??= Encoding.UTF8.GetBytes(_currencySymbol));
390internal byte[]? CurrencySymbolUtf8 => _currencySymbolUtf8 ??= Encoding.UTF8.GetBytes(_currencySymbol);
433Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_nanSymbolUtf8 ??= Encoding.UTF8.GetBytes(_nanSymbol));
518Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_negativeInfinitySymbolUtf8 ??= Encoding.UTF8.GetBytes(_negativeInfinitySymbol));
541Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_negativeSignUtf8 ??= Encoding.UTF8.GetBytes(_negativeSign));
577Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_numberDecimalSeparatorUtf8 ??= Encoding.UTF8.GetBytes(_numberDecimalSeparator));
598Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_numberGroupSeparatorUtf8 ??= Encoding.UTF8.GetBytes(_numberGroupSeparator));
635Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_positiveInfinitySymbolUtf8 ??= Encoding.UTF8.GetBytes(_positiveInfinitySymbol));
658Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_positiveSignUtf8 ??= Encoding.UTF8.GetBytes(_positiveSign));
694Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_percentDecimalSeparatorUtf8 ??= Encoding.UTF8.GetBytes(_percentDecimalSeparator));
715Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_percentGroupSeparatorUtf8 ??= Encoding.UTF8.GetBytes(_percentGroupSeparator));
736Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_percentSymbolUtf8 ??= Encoding.UTF8.GetBytes(_percentSymbol));
758Unsafe.BitCast<ReadOnlySpan<byte>, ReadOnlySpan<TChar>>(_perMilleSymbolUtf8 ??= Encoding.UTF8.GetBytes(_perMilleSymbol));
src\libraries\System.Private.CoreLib\src\System\IO\File.cs (37)
23private static Encoding? s_UTF8NoBOM;
26private static Encoding UTF8NoBOM => s_UTF8NoBOM ??= new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
625=> ReadAllText(path, Encoding.UTF8);
627public static string ReadAllText(string path, Encoding encoding)
657/// include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the <see cref="WriteAllText(string, ReadOnlySpan{char}, Encoding)"/> method.
662public static void WriteAllText(string path, string? contents, Encoding encoding)
688public static void WriteAllText(string path, ReadOnlySpan<char> contents, Encoding encoding)
865=> ReadAllLines(path, Encoding.UTF8);
867public static string[] ReadAllLines(string path, Encoding encoding)
884=> ReadLines(path, Encoding.UTF8);
886public static IEnumerable<string> ReadLines(string path, Encoding encoding)
900=> ReadLinesAsync(path, Encoding.UTF8, cancellationToken);
909public static IAsyncEnumerable<string> ReadLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken = default)
923public static void WriteAllLines(string path, string[] contents, Encoding encoding)
926public static void WriteAllLines(string path, IEnumerable<string> contents, Encoding encoding)
974public static void AppendAllText(string path, string? contents, Encoding encoding)
1004public static void AppendAllText(string path, ReadOnlySpan<char> contents, Encoding encoding)
1014public static void AppendAllLines(string path, IEnumerable<string> contents, Encoding encoding)
1079private static StreamReader AsyncStreamReader(string path, Encoding encoding)
1085=> ReadAllTextAsync(path, Encoding.UTF8, cancellationToken);
1087public static Task<string> ReadAllTextAsync(string path, Encoding encoding, CancellationToken cancellationToken = default)
1096private static async Task<string> InternalReadAllTextAsync(string path, Encoding encoding, CancellationToken cancellationToken)
1144public static Task WriteAllTextAsync(string path, string? contents, Encoding encoding, CancellationToken cancellationToken = default)
1157public static Task WriteAllTextAsync(string path, ReadOnlyMemory<char> contents, Encoding encoding, CancellationToken cancellationToken = default)
1291=> ReadAllLinesAsync(path, Encoding.UTF8, cancellationToken);
1293public static Task<string[]> ReadAllLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken = default)
1302private static async Task<string[]> InternalReadAllLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken)
1325public static Task WriteAllLinesAsync(string path, IEnumerable<string> contents, Encoding encoding, CancellationToken cancellationToken = default) =>
1328private static Task WriteAllLinesAsync(string path, IEnumerable<string> contents, Encoding encoding, bool append, CancellationToken cancellationToken)
1382public static Task AppendAllTextAsync(string path, string? contents, Encoding encoding, CancellationToken cancellationToken = default)
1394public static Task AppendAllTextAsync(string path, ReadOnlyMemory<char> contents, Encoding encoding, CancellationToken cancellationToken = default)
1409public static Task AppendAllLinesAsync(string path, IEnumerable<string> contents, Encoding encoding, CancellationToken cancellationToken = default) =>
1452private static void Validate(string path, Encoding encoding)
1503private static void WriteToFile(string path, FileMode mode, ReadOnlySpan<char> contents, Encoding encoding)
1559private static async Task WriteToFileAsync(string path, FileMode mode, ReadOnlyMemory<char> contents, Encoding encoding, CancellationToken cancellationToken)
1610private static long GetPreallocationSize(FileMode mode, ReadOnlySpan<char> contents, Encoding encoding, int preambleSize)
1627private static async IAsyncEnumerable<string> IterateFileLinesAsync(StreamReader sr, string path, Encoding encoding, CancellationToken ctEnumerable, [EnumeratorCancellation] CancellationToken ctEnumerator = default)
src\libraries\System.Private.CoreLib\src\System\IO\StreamReader.cs (20)
32private Encoding _encoding = null!; // only null in NullStreamReader where this is never used
110: this(stream, Encoding.UTF8, detectEncodingFromByteOrderMarks, DefaultBufferSize, false)
114public StreamReader(Stream stream, Encoding? encoding)
119public StreamReader(Stream stream, Encoding? encoding, bool detectEncodingFromByteOrderMarks)
134public StreamReader(Stream stream, Encoding? encoding, bool detectEncodingFromByteOrderMarks, int bufferSize)
139public StreamReader(Stream stream, Encoding? encoding = null, bool detectEncodingFromByteOrderMarks = true, int bufferSize = -1, bool leaveOpen = false)
158_encoding = encoding ??= Encoding.UTF8;
186: this(path, Encoding.UTF8, detectEncodingFromByteOrderMarks, DefaultBufferSize)
190public StreamReader(string path, Encoding? encoding)
195public StreamReader(string path, Encoding? encoding, bool detectEncodingFromByteOrderMarks)
200public StreamReader(string path, Encoding? encoding, bool detectEncodingFromByteOrderMarks, int bufferSize)
206: this(path, Encoding.UTF8, true, options)
210public StreamReader(string path, Encoding? encoding, bool detectEncodingFromByteOrderMarks, FileStreamOptions options)
269public virtual Encoding CurrentEncoding => _encoding;
480_encoding = Encoding.BigEndianUnicode;
489_encoding = Encoding.Unicode;
495_encoding = Encoding.UTF32;
503_encoding = Encoding.UTF8;
1412public override Encoding CurrentEncoding => Encoding.Unicode;
src\libraries\System.Private.CoreLib\src\System\IO\StreamWriter.cs (9)
34private readonly Encoding _encoding;
73private static Encoding UTF8NoBOM => EncodingCache.UTF8NoBOM;
80public StreamWriter(Stream stream, Encoding? encoding)
89public StreamWriter(Stream stream, Encoding? encoding, int bufferSize)
94public StreamWriter(Stream stream, Encoding? encoding = null, int bufferSize = -1, bool leaveOpen = false)
143public StreamWriter(string path, bool append, Encoding? encoding)
148public StreamWriter(string path, bool append, Encoding? encoding, int bufferSize) :
158public StreamWriter(string path, Encoding? encoding, FileStreamOptions options)
344public override Encoding Encoding => _encoding;
src\libraries\System.Private.CoreLib\src\System\String.cs (4)
247return CreateStringFromEncoding(pb, numBytes, Encoding.UTF8);
256public extern unsafe String(sbyte* value, int startIndex, int length, Encoding enc);
258private static unsafe string Ctor(sbyte* value, int startIndex, int length, Encoding? enc)
534byte* bytes, int byteLength, Encoding encoding)
src\libraries\System.Private.CoreLib\src\System\Text\Encoding.cs (40)
83public static Encoding Default => s_defaultEncoding;
172public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes)
184public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding,
200public static Encoding GetEncoding(int codepage)
202Encoding? result = FilterDisallowedEncodings(EncodingProvider.GetEncodingFromProvider(codepage));
255public static Encoding GetEncoding(int codepage,
258Encoding? baseEncoding = FilterDisallowedEncodings(EncodingProvider.GetEncodingFromProvider(codepage, encoderFallback, decoderFallback));
267Encoding fallbackEncoding = (Encoding)baseEncoding.Clone();
276public static Encoding GetEncoding(string name)
288public static Encoding GetEncoding(string name,
301private static Encoding? FilterDisallowedEncodings(Encoding? encoding)
501Encoding newEncoding = (Encoding)this.MemberwiseClone();
517public static Encoding ASCII => ASCIIEncoding.s_default;
520public static Encoding Latin1 => Latin1Encoding.s_default;
1019public static Encoding Unicode => UnicodeEncoding.s_littleEndianDefault;
1027public static Encoding BigEndianUnicode => UnicodeEncoding.s_bigEndianDefault;
1033public static Encoding UTF7 => UTF7Encoding.s_default;
1038public static Encoding UTF8 => UTF8Encoding.s_default;
1043public static Encoding UTF32 => UTF32Encoding.s_default;
1050private static Encoding BigEndianUTF32 => UTF32Encoding.s_bigEndianDefault;
1053value is Encoding that &&
1062/// Creates a <see cref="Stream"/> which serves to transcode data between an inner <see cref="Encoding"/>
1063/// and an outer <see cref="Encoding"/>, similar to <see cref="Convert"/>.
1066/// <param name="innerStreamEncoding">The <see cref="Encoding"/> associated with <paramref name="innerStream"/>.</param>
1067/// <param name="outerStreamEncoding">The <see cref="Encoding"/> associated with the <see cref="Stream"/> returned
1079public static Stream CreateTranscodingStream(Stream innerStream, Encoding innerStreamEncoding, Encoding outerStreamEncoding, bool leaveOpen = false)
1147private readonly Encoding _encoding;
1149public DefaultEncoder(Encoding encoding)
1199private readonly Encoding _encoding;
1201public DefaultDecoder(Encoding encoding)
1260private readonly Encoding _enc;
1267internal unsafe EncodingCharBuffer(Encoding enc, DecoderNLS? decoder, char* charStart, int charCount,
1410private readonly Encoding _enc;
1414internal unsafe EncodingByteBuffer(Encoding inEncoding, EncoderNLS? inEncoder,
src\libraries\System.Private.CoreLib\src\System\Text\EncodingProvider.cs (16)
14public abstract Encoding? GetEncoding(string name);
15public abstract Encoding? GetEncoding(int codepage);
18public virtual Encoding? GetEncoding(string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
20Encoding? enc = GetEncoding(name);
23enc = (Encoding)enc.Clone();
31public virtual Encoding? GetEncoding(int codepage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
33Encoding? enc = GetEncoding(codepage);
36enc = (Encoding)enc.Clone();
80internal static Encoding? GetEncodingFromProvider(int codepage)
88Encoding? enc = provider.GetEncoding(codepage);
119internal static Encoding? GetEncodingFromProvider(string encodingName)
127Encoding? enc = provider.GetEncoding(encodingName);
135internal static Encoding? GetEncodingFromProvider(int codepage, EncoderFallback enc, DecoderFallback dec)
143Encoding? encoding = provider.GetEncoding(codepage, enc, dec);
151internal static Encoding? GetEncodingFromProvider(string encodingName, EncoderFallback enc, DecoderFallback dec)
159Encoding? encoding = provider.GetEncoding(encodingName, enc, dec);
System.Private.CoreLib.Generators (4)
System.Private.DataContractSerialization (95)
System\Runtime\Serialization\Json\JsonEncodingStreamWrapper.cs (8)
25private Encoding? _encoding;
32public JsonEncodingStreamWrapper(Stream stream, Encoding? encoding, bool isReader)
124public static ArraySegment<byte> ProcessBuffer(byte[] buffer, int offset, int count, Encoding? encoding)
202_byteCount = Encoding.UTF8.GetBytes(_chars, 0, charCount, _bytes, 0);
285private static Encoding GetEncoding(SupportedEncoding e) =>
303private static SupportedEncoding GetSupportedEncoding(Encoding? encoding)
429private void InitForReading(Stream inputStream, Encoding? expectedEncoding)
462private void InitForWriting(Stream outputStream, Encoding writeEncoding)
System\Runtime\Serialization\Json\JsonReaderWriterFactory.cs (7)
29public static XmlDictionaryReader CreateJsonReader(Stream stream, Encoding? encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose? onClose)
41public static XmlDictionaryReader CreateJsonReader(byte[] buffer, int offset, int count, Encoding? encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose? onClose)
50return CreateJsonWriter(stream, Encoding.UTF8, true);
53public static XmlDictionaryWriter CreateJsonWriter(Stream stream, Encoding encoding)
58public static XmlDictionaryWriter CreateJsonWriter(Stream stream, Encoding encoding, bool ownsStream)
63public static XmlDictionaryWriter CreateJsonWriter(Stream stream, Encoding encoding, bool ownsStream, bool indent)
68public static XmlDictionaryWriter CreateJsonWriter(Stream stream, Encoding encoding, bool ownsStream, bool indent, string? indentChars)
System\Runtime\Serialization\Json\XmlJsonReader.cs (10)
603XmlExceptionHelper.ThrowTokenExpected(this, "false", Encoding.UTF8.GetString(buffer, offset, 5));
611XmlExceptionHelper.ThrowTokenExpected(this, "false", Encoding.UTF8.GetString(buffer, offset, 4) + (char)ch);
624XmlExceptionHelper.ThrowTokenExpected(this, "true", Encoding.UTF8.GetString(buffer, offset, 4));
632XmlExceptionHelper.ThrowTokenExpected(this, "true", Encoding.UTF8.GetString(buffer, offset, 4) + (char)ch);
645XmlExceptionHelper.ThrowTokenExpected(this, "null", Encoding.UTF8.GetString(buffer, offset, 4));
658XmlExceptionHelper.ThrowTokenExpected(this, "null", Encoding.UTF8.GetString(buffer, offset, 4) + (char)ch);
774public void SetInput(byte[] buffer, int offset, int count, Encoding? encoding, XmlDictionaryReaderQuotas quotas,
797public void SetInput(Stream stream, Encoding? encoding, XmlDictionaryReaderQuotas quotas,
1196string bufferAsString = Encoding.UTF8.GetString(buffer, offset, 4);
1207bufferAsString = Encoding.UTF8.GetString(buffer, offset, 4);
System\Xml\EncodingStreamWrapper.cs (9)
40private Encoding? _encoding;
54public EncodingStreamWrapper(Stream stream, Encoding? encoding)
123private static Encoding GetEncoding(SupportedEncoding e) =>
132private static Encoding GetSafeEncoding(SupportedEncoding e) =>
150private static SupportedEncoding GetSupportedEncoding(Encoding? encoding)
165public EncodingStreamWrapper(Stream stream, Encoding encoding, bool emitBOM)
432internal static ArraySegment<byte> ProcessBuffer(byte[] buffer, int offset, int count, Encoding? encoding)
453Encoding localEnc;
612_byteCount = Encoding.UTF8.GetBytes(_chars, 0, charCount, _bytes, 0);
System\Xml\XmlCanonicalWriter.cs (7)
184_element.prefixLength = Encoding.UTF8.GetByteCount(prefix);
186_element.localNameLength = Encoding.UTF8.GetByteCount(localName);
254if (string.Equals(Encoding.UTF8.GetString(_xmlnsBuffer!, xmlnsAttribute.prefixOffset, xmlnsAttribute.prefixLength), _inclusivePrefixes[i], StringComparison.Ordinal))
371xmlnsAttribute.prefixLength = Encoding.UTF8.GetBytes(prefix, 0, prefix.Length, _xmlnsBuffer, _xmlnsOffset);
374xmlnsAttribute.nsLength = Encoding.UTF8.GetBytes(ns, 0, ns.Length, _xmlnsBuffer, _xmlnsOffset);
424_attribute.prefixLength = Encoding.UTF8.GetByteCount(prefix);
426_attribute.localNameLength = Encoding.UTF8.GetByteCount(localName);
System\Xml\XmlDictionaryReader.cs (12)
101Encoding? encoding,
115public static XmlDictionaryReader CreateTextReader(Stream stream, Encoding? encoding,
124public static XmlDictionaryReader CreateMtomReader(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas)
128return CreateMtomReader(stream, new Encoding[1] { encoding }, quotas);
131public static XmlDictionaryReader CreateMtomReader(Stream stream, Encoding[] encodings, XmlDictionaryReaderQuotas quotas)
136public static XmlDictionaryReader CreateMtomReader(Stream stream, Encoding[] encodings, string? contentType, XmlDictionaryReaderQuotas quotas)
141public static XmlDictionaryReader CreateMtomReader(Stream stream, Encoding[] encodings, string? contentType,
147public static XmlDictionaryReader CreateMtomReader(byte[] buffer, int offset, int count, Encoding encoding, XmlDictionaryReaderQuotas quotas)
151return CreateMtomReader(buffer, offset, count, new Encoding[1] { encoding }, quotas);
154public static XmlDictionaryReader CreateMtomReader(byte[] buffer, int offset, int count, Encoding[] encodings, XmlDictionaryReaderQuotas quotas)
159public static XmlDictionaryReader CreateMtomReader(byte[] buffer, int offset, int count, Encoding[] encodings, string? contentType, XmlDictionaryReaderQuotas quotas)
164public static XmlDictionaryReader CreateMtomReader(byte[] buffer, int offset, int count, Encoding[] encodings, string? contentType,
System\Xml\XmlDictionaryWriter.cs (4)
47public static XmlDictionaryWriter CreateTextWriter(Stream stream, Encoding encoding)
52public static XmlDictionaryWriter CreateTextWriter(Stream stream, Encoding encoding, bool ownsStream)
60public static XmlDictionaryWriter CreateMtomWriter(Stream stream, Encoding encoding, int maxSizeInBytes, string startInfo)
65public static XmlDictionaryWriter CreateMtomWriter(Stream stream, Encoding encoding, int maxSizeInBytes, string startInfo, string? boundary, string? startUri, bool writeMessageHeaders, bool ownsStream)
System\Xml\XmlNodeWriter.cs (8)
37WriteStartElement(Encoding.UTF8.GetString(prefixBuffer, prefixOffset, prefixLength), Encoding.UTF8.GetString(localNameBuffer, localNameOffset, localNameLength));
52WriteEndElement(Encoding.UTF8.GetString(prefixBuffer, prefixOffset, prefixLength), Encoding.UTF8.GetString(localNameBuffer, localNameOffset, localNameLength));
57WriteXmlnsAttribute(Encoding.UTF8.GetString(prefixBuffer, prefixOffset, prefixLength), Encoding.UTF8.GetString(nsBuffer, nsOffset, nsLength));
63WriteStartAttribute(Encoding.UTF8.GetString(prefixBuffer, prefixOffset, prefixLength), Encoding.UTF8.GetString(localNameBuffer, localNameOffset, localNameLength));
System\Xml\XmlUTF8TextReader.cs (6)
20void SetInput(byte[] buffer, int offset, int count, Encoding? encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose? onClose);
21void SetInput(Stream stream, Encoding? encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose? onClose);
556public void SetInput(byte[] buffer, int offset, int count, Encoding? encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose? onClose)
572public void SetInput(Stream stream, Encoding? encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose? onClose)
646XmlExceptionHelper.ThrowTokenExpected(this, "?>", Encoding.UTF8.GetString(buffer, offset, 2));
1056XmlExceptionHelper.ThrowTokenExpected(this, "[CDATA[", Encoding.UTF8.GetString(buffer, offset, 7));
System.Private.Windows.Core (4)
System.Private.Xml (84)
System\Xml\Core\XmlTextReaderImpl.cs (31)
214private Encoding? _reportedEncoding;
508Encoding? enc = context?.Encoding;
535InitStringInput(string.Empty, Encoding.Unicode, xmlFragment);
540InitStringInput(context.BaseURI, Encoding.Unicode, xmlFragment);
555InitStringInput((context == null) ? string.Empty : context.BaseURI, Encoding.Unicode, $"<?xml {xmlFragment}?>");
651Encoding? enc = null;
728Encoding? enc = null;
813InitStringInput(string.Empty, Encoding.Unicode, xmlFragment);
2028internal Encoding? Encoding
2620InitStringInput(baseUri, Encoding.Unicode, internalDtd);
2818private void InitStreamInput(Stream stream, Encoding? encoding)
2823private void InitStreamInput(string baseUriStr, Stream stream, Encoding? encoding)
2829private void InitStreamInput(Uri? baseUri, Stream stream, Encoding? encoding)
2835private void InitStreamInput(Uri? baseUri, string baseUriStr, Stream stream, Encoding? encoding)
2840private void InitStreamInput(Uri? baseUri, string baseUriStr, Stream stream, byte[]? bytes, int byteCount, Encoding? encoding)
2936_ps.encoding = Encoding.Unicode;
2944private void InitStringInput(string baseUriStr, Encoding? originalEncoding, string str)
3087private Encoding? DetectEncoding()
3123return Encoding.BigEndianUnicode;
3132return Encoding.Unicode;
3141return Encoding.Unicode;
3150return Encoding.BigEndianUnicode;
3172private void SetupEncoding(Encoding? encoding)
3177_ps.encoding = Encoding.UTF8;
3204private void SwitchEncoding(Encoding newEncoding)
3219private Encoding CheckEncoding(string newEncodingName)
3250Encoding? newEncoding = null;
3259newEncoding = Encoding.GetEncoding(newEncodingName);
3614Encoding? encoding = null;
8018Encoding? enc = _ps.encoding;
8035Encoding? enc = _ps.encoding;
System.Private.Xml.Linq (4)
System.Reflection.Emit (1)
System.Reflection.Metadata (8)
System.Reflection.MetadataLoadContext (2)
System.Resources.Extensions (6)
System.Resources.Writer (3)
System.Runtime (1)
System.Security.Cryptography (23)
System.Security.Cryptography.Pkcs (10)
System.Security.Cryptography.Xml (18)
System.ServiceModel.Federation (2)
System.ServiceModel.Http.Tests (21)
System.ServiceModel.NetFramingBase (3)
System.ServiceModel.NetNamedPipe (1)
System.ServiceModel.Primitives.Tests (6)
System.Text.Encoding (1)
System.Text.Encoding.CodePages (9)
System.Text.Json (4)
System.Text.Json.SourceGeneration (2)
System.Web.HttpUtility (25)
System\Web\HttpUtility.cs (17)
81public static NameValueCollection ParseQueryString(string query) => ParseQueryString(query, Encoding.UTF8);
83public static NameValueCollection ParseQueryString(string query, Encoding encoding)
161public static string? UrlEncode(string? str) => UrlEncode(str, Encoding.UTF8);
167public static string? UrlEncode(string? str, Encoding e) =>
168str == null ? null : Encoding.ASCII.GetString(UrlEncodeToBytes(str, e));
171public static string? UrlEncode(byte[]? bytes) => bytes == null ? null : Encoding.ASCII.GetString(UrlEncodeToBytes(bytes));
174public static string? UrlEncode(byte[]? bytes, int offset, int count) => bytes == null ? null : Encoding.ASCII.GetString(UrlEncodeToBytes(bytes, offset, count));
177public static byte[]? UrlEncodeToBytes(string? str) => UrlEncodeToBytes(str, Encoding.UTF8);
184public static byte[]? UrlEncodeUnicodeToBytes(string? str) => str == null ? null : Encoding.ASCII.GetBytes(UrlEncodeUnicode(str));
187public static string? UrlDecode(string? str) => UrlDecode(str, Encoding.UTF8);
190public static string? UrlDecode(byte[]? bytes, Encoding e) => bytes == null ? null : UrlDecode(bytes, 0, bytes.Length, e);
193public static byte[]? UrlDecodeToBytes(string? str) => UrlDecodeToBytes(str, Encoding.UTF8);
196public static byte[]? UrlDecodeToBytes(string? str, Encoding e)
219public static byte[]? UrlEncodeToBytes(string? str, Encoding e) => str == null ? null : HttpEncoder.UrlEncode(str, e);
229public static string? UrlDecode(string? str, Encoding e) => HttpEncoder.UrlDecode(str, e);
231private static string UrlDecode(ReadOnlySpan<char> str, Encoding e) => HttpEncoder.UrlDecode(str, e);
234public static string? UrlDecode(byte[]? bytes, int offset, int count, Encoding e) =>
System.Web.Services.Description (1)
System.Windows.Forms (30)
System.Windows.Forms.Analyzers.CSharp.Tests (1)
System.Windows.Forms.Analyzers.Tests (1)
System.Windows.Forms.Design (6)
System.Windows.Forms.Design.Tests (4)
System.Windows.Forms.Tests (42)
System.Windows.Forms.UI.IntegrationTests (1)
System.Xaml (1)
Templates.Blazor.Tests (5)
Templates.Blazor.WebAssembly.Auth.Tests (5)
Templates.Blazor.WebAssembly.Tests (5)
Templates.Mvc.Tests (5)
Templates.Tests (6)
Test.Utilities (3)
TestReferenceAssembly (6)
Text.Analyzers (3)
UIAutomationTypes (2)
UnitTests.Common (10)
vbc (9)
VBCSCompiler (9)
VBCSCompiler.UnitTests (6)
CompilerServerTests.cs (6)
149private static (T Result, string Output) UseTextWriter<T>(Encoding encoding, Func<TextWriter, T> func)
182Encoding redirectEncoding = null,
330var result = RunCommandLineCompiler(CSharpCompilerClientExecutable, $"/shared:{serverData.PipeName} /nologo hello.cs", _tempDirectory, files, redirectEncoding: Encoding.ASCII, shouldRunOnServer: false);
371redirectEncoding: Encoding.ASCII,
1155redirectEncoding: Encoding.ASCII);
1178redirectEncoding: Encoding.ASCII);
VisualBasicErrorFactsGenerator (1)
VisualBasicSyntaxGenerator (6)
Program.vb (6)
78Using output As New StreamWriter(New FileStream(mainFile, FileMode.Create, FileAccess.Write), Encoding.UTF8)
126Using output As New StreamWriter(New FileStream(outputFile, FileMode.Create, FileAccess.Write), Encoding.UTF8)
142Using output As New StreamWriter(New FileStream(outputFile, FileMode.Create, FileAccess.Write), Encoding.UTF8)
161Using output As New StreamWriter(New FileStream(mainFile, FileMode.Create, FileAccess.Write), Encoding.UTF8)
172Using output As New StreamWriter(New FileStream(syntaxFile, FileMode.Create, FileAccess.Write), Encoding.UTF8)
178Using output As New StreamWriter(New FileStream(internalFile, FileMode.Create, FileAccess.Write), Encoding.UTF8)
WebSocketSample (2)
WebTransportInteractiveSampleApp (2)
WebTransportSampleApp (1)