Method overriding: retarget net10.0, add hiding and abstract samples, new tests - #2204
Open
vladimir-pecanac-main wants to merge 1 commit into
Conversation
… new tests Retarget MethodOverridingInCSharp and Tests to net10.0 and bump the test stack (Microsoft.NET.Test.Sdk 18.10.0, xunit 2.9.3, xunit.runner.visualstudio 4.0.0, coverlet.collector 10.0.1), which also clears the NU1903 advisory the old stack pulled in transitively through Newtonsoft.Json 9.0.1. Mark Shape.Color as required so the project builds with no CS8618 warning; every sample already sets Color in an object initializer. Convert Program.cs to top-level statements, matching the form the article shows, and print the new hiding example. Add Sketch, a derived class whose Draw() uses new instead of override, and an Abstract namespace holding the abstract variant the article demonstrates but the repo never carried. Add HidingTest, BaseCallTest and AbstractTest. BaseCallTest normalises line endings before splitting because Cube.Draw() uses StringBuilder.AppendLine and CI runs on ubuntu-latest. Drop two no-argument string.Format() calls in Test.cs.
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.
Updates the
csharp-methods/MethodOverridingInCSharpsample for the Method Overriding in C# article.MethodOverridingInCSharpandTestsfromnet7.0tonet10.0.Microsoft.NET.Test.Sdk18.10.0,xunit2.9.3,xunit.runner.visualstudio4.0.0,coverlet.collector10.0.1. This also clearsNU1903(a known high severity advisory onNewtonsoft.Json9.0.1, pulled in transitively by the old stack).Shape.Colorbecomesrequired, which clearsCS8618. Every sample already setsColorin an object initializer.Program.csmoves to top-level statements, which is the form the article prints, and gains the two lines that demonstrate hiding.Sketchclass: a derived class whoseDraw()usesnewinstead ofoverride, for the article's new section onoverrideversusnew.Abstractnamespace holding the article's abstract variant ofShape,CircleandSquare, which the repo never carried.HidingTest(three cases),BaseCallTestandAbstractTest.BaseCallTestnormalises line endings before splitting, becauseCube.Draw()builds its result withStringBuilder.AppendLine()and CI runs onubuntu-latest.string.Format()calls inTest.cs.Verified locally on SDK 10.0.302 / runtime .NET 10.0.10:
dotnet build -c Releasegives 0 warnings and 0 errors, anddotnet test -c Release --filter "FullyQualifiedName!~Live"gives 7 passed, 0 failed, 0 skipped.