Skip to content

Method overriding: retarget net10.0, add hiding and abstract samples, new tests - #2204

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/80738-csharp-method-overriding
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/80738-csharp-method-overriding

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Updates the csharp-methods/MethodOverridingInCSharp sample for the Method Overriding in C# article.

  • Retarget MethodOverridingInCSharp and Tests from net7.0 to net10.0.
  • 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. This also clears NU1903 (a known high severity advisory on Newtonsoft.Json 9.0.1, pulled in transitively by the old stack).
  • Shape.Color becomes required, which clears CS8618. Every sample already sets Color in an object initializer.
  • Program.cs moves to top-level statements, which is the form the article prints, and gains the two lines that demonstrate hiding.
  • New Sketch class: a derived class whose Draw() uses new instead of override, for the article's new section on override versus new.
  • New Abstract namespace holding the article's abstract variant of Shape, Circle and Square, which the repo never carried.
  • New tests: HidingTest (three cases), BaseCallTest and AbstractTest. BaseCallTest normalises line endings before splitting, because Cube.Draw() builds its result with StringBuilder.AppendLine() and CI runs on ubuntu-latest.
  • Dropped two no-argument string.Format() calls in Test.cs.

Verified locally on SDK 10.0.302 / runtime .NET 10.0.10: dotnet build -c Release gives 0 warnings and 0 errors, and dotnet test -c Release --filter "FullyQualifiedName!~Live" gives 7 passed, 0 failed, 0 skipped.

… 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.
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