Converting string to byte array: retarget net10.0, add the reverse direction - #2178
Open
vladimir-pecanac-main wants to merge 1 commit into
Conversation
…rection
- All four projects retargeted net8.0 -> net10.0.
- Packages: Microsoft.NET.Test.Sdk 18.9.0, xunit 2.9.3,
xunit.runner.visualstudio 4.0.0, coverlet.collector 10.0.1,
BenchmarkDotNet 0.13.11 -> 0.15.8.
- New MessageConversion.ConvertUTF8BytesToString, the byte[] -> string half of
the pair, with tests for the matching UTF-8 round trip, the lossy ASCII round
trip ("cafe ??"), and the U+FFFD replacement for an invalid byte.
- Tests backing the article's method-comparison table, so no row rests on a
scratch console app: (byte)'A-macron' truncates silently to 0 while
Convert.ToByte on the same char throws OverflowException.
- Test proving Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
makes GetEncoding(1252) resolve, and that the two overloads fail differently
before it: GetEncoding(1252) throws NotSupportedException while
GetEncoding("windows-1252") throws ArgumentException. No PackageReference is
needed for this on net10.0; the provider ships in the shared framework.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Retargets
collections-arrays/ConvertingStringToByteArraytonet10.0and adds the byte-array-to-string direction the sample was missing.Retarget and packages
net8.0->net10.0.Microsoft.NET.Test.Sdk17.6.0 -> 18.9.0,xunit2.4.2 -> 2.9.3,xunit.runner.visualstudio2.4.5 -> 4.0.0,coverlet.collector6.0.0 -> 10.0.1,BenchmarkDotNet0.13.11 -> 0.15.8.New method
MessageConversion.ConvertUTF8BytesToString(byte[]), the other half of the pair.New tests (10 passing, previously 4)
"cafe [emoji]"returns"caf? ??", silently.U+FFFDrather than throwing.(byte)of a char aboveU+00FFtruncates to0;Convert.ToByteon the same char throwsOverflowException. These two back the comparison table in the article, so no table row rests on a scratch console app.Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)makesGetEncoding(1252)resolve, and before it the two overloads fail differently:GetEncoding(1252)throwsNotSupportedExceptionwhileGetEncoding("windows-1252")throwsArgumentException. NoSystem.Text.Encoding.CodePagesPackageReference is needed onnet10.0, the provider ships in the shared framework (adding it raisesNU1510).Build is clean with zero warnings; all 10 tests pass on .NET 10.0.10 / SDK 10.0.302. Both benchmark classes were re-run on
net10.0and the article's printed tables are being replaced with that output.