Parse and TryParse: retarget net10.0, MSTest 4.3.3, cover the .NET 7/8 overloads - #2169
Open
vladimir-pecanac-main wants to merge 1 commit into
Open
Conversation
…8 overloads Retarget both projects from net6.0 to net10.0 and bring the test stack up to the current line: Microsoft.NET.Test.Sdk 18.9.0, MSTest 4.3.3, coverlet 10.0.1. MSTest 4.x removes Assert.ThrowsException<T>, so the twelve call sites across the eight negative tests move to Assert.Throws<T>. Add two tests for overloads the sample did not exercise: the IFormatProvider overload introduced with IParsable<T>, and the UTF-8 ReadOnlySpan<byte> overload introduced with IUtf8SpanParsable<T>. Two null call sites needed a fix under <Nullable>enable</Nullable> on net10.0: int.Parse(null) emitted CS8625 and is now int.Parse(null!), and int.TryParse(null, out _) no longer compiles at all (CS0121, ambiguous between the string and ReadOnlySpan<byte> overloads) and is now (string?)null. Program.cs moves to a file-scoped namespace. Build: 0 warnings. Tests: 20/20 passing on SDK 10.0.302.
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 the
ParseandTryParsesample to .NET 10 and covers the two overloads the article's new section introduces.Changes
net6.0->net10.0on bothParseAndTryParseInCSharp.csprojandTests/Tests.csproj.Microsoft.NET.Test.Sdk16.11.0 -> 18.9.0,MSTest.TestAdapter/MSTest.TestFramework2.2.7 -> 4.3.3,coverlet.collector3.1.0 -> 10.0.1.Assert.ThrowsException<T>->Assert.Throws<T>, twelve call sites across the eight negative tests. MSTest 4.x removesThrowsException<T>outright (CS0117), so this is required by the bump rather than optional tidying.int.TryParse(string?, IFormatProvider?, out int)(theIParsable<T>shape) andint.TryParse(ReadOnlySpan<byte>, out int)(theIUtf8SpanParsable<T>shape).int.Parse(null)emittedCS8625under<Nullable>enable</Nullable>. Nowint.Parse(null!). A(string?)nullcast does not clear it, because the parameter is annotated non-nullable.int.TryParse(null, out int nullNum)no longer compiles at all on net10.0:CS0121, ambiguous betweenint.TryParse(string?, out int)and the .NET 8int.TryParse(ReadOnlySpan<byte>, out int). Now(string?)null, which compiles and still returnsfalse.ReadOnlySpan<char> value = null;needed no change. Checked explicitly against current C# conversion rules on net10.0: it still compiles with no warning.Program.csto a file-scoped namespace. The console project is an emptyMain; everything the article shows lives in the tests.Verification
dotnet build -c Release: 0 warnings, 0 errorsdotnet test -c Release: 20/20 passing, SDK 10.0.302The sample carries no platform-bound or environment-bound test, so nothing here needs
Livenaming and the workflow is untouched.