Skip to content

Convert byte array to hex: retarget net10.0, ToHexStringLower, namespace fix - #2216

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/91777-csharp-convert-byte-array-to-hexadecimal-string
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/91777-csharp-convert-byte-array-to-hexadecimal-string

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Retargets collections-arrays/ConvertByteArrayToHex to .NET 10 and fixes what the retarget exposed.

Retarget and packages

  • All four projects net7.0 -> net10.0 (Library, Console, Benchmark, UnitTests). AllowUnsafeBlocks stays on the library for the .NET Standard 2.0 lookup method.
  • xunit 2.4.2 -> 2.9.3, xunit.runner.visualstudio 2.4.5 -> 4.0.0, Microsoft.NET.Test.Sdk 17.6.0 -> 18.10.1, coverlet.collector 6.0.0 -> 10.0.1, BenchmarkDotNet 0.13.5 -> 0.15.8. Each version was re-queried against the NuGet flat-container index on the day this PR opened and is the newest non-prerelease entry.
  • Drops CommunityToolkit.HighPerformance 8.2.0 from the benchmark project: no .cs file in the folder references it.

Code

  • ConversionHelpers.ToHexWithConvert() takes the lowercase branch through Convert.ToHexStringLower() (.NET 9 and later) instead of Convert.ToHexString(...).ToLowerInvariant(), which removes a second string allocation. ConvertByteArrayToHexLowerBenchmarks gains ConvertToLowerHexUsingConvertAndToLowerInvariant so the old path is still measured beside the new one.
  • LookupTables.cs declared namespace ConvertByteArrayHexLibrary;, missing the To, which forced a stray using in two files. The namespace is corrected and both using ConvertByteArrayHexLibrary; lines are dropped (src/ConvertByteArrayToHexLibrary/ConversionHelpers.cs and test/ConvertByteArrayToHexUnitTests/ConvertByteArrayLookupTablesTests.cs).

Verification
dotnet build -c Release: 0 warnings, 0 errors. dotnet test: 69 of 69 passing. SDK 10.0.302, runtime 10.0.10. Both benchmark classes were re-run on net10.0 for the article's benchmark table.

…ace fix

Retargets all four projects in collections-arrays/ConvertByteArrayToHex from net7.0 to
net10.0 and moves the package set forward: xunit 2.9.3, xunit.runner.visualstudio 4.0.0,
Microsoft.NET.Test.Sdk 18.10.1, coverlet.collector 10.0.1, BenchmarkDotNet 0.15.8.

Drops the CommunityToolkit.HighPerformance reference from the benchmark project, which no
source file in the folder uses.

ToHexWithConvert() now calls Convert.ToHexStringLower() for the lowercase case instead of
Convert.ToHexString(...).ToLowerInvariant(), which saves a second string allocation, and the
lower benchmark class gains a method that measures the old path beside the new one.

Fixes the namespace typo in LookupTables.cs (ConvertByteArrayHexLibrary, missing the To) and
drops both stray using directives it forced, in ConversionHelpers.cs and in
ConvertByteArrayLookupTablesTests.cs.

Build: 0 warnings, 0 errors. Tests: 69 of 69 passing on SDK 10.0.302 / runtime 10.0.10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant