Skip to content

Custom naming policy: retarget net10.0, consolidate four projects to two, NUnit 4 - #2155

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/101312-naming-policy
Open

Custom naming policy: retarget net10.0, consolidate four projects to two, NUnit 4#2155
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/101312-naming-policy

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample update for the republished article "JsonNamingPolicy in C#: Built-in and Custom Naming Policies" (/csharp-custom-naming-policy-for-json/).

What changed

  • net7 -> net10.0 on both surviving projects. The moniker was the non-canonical net7, and it is out of support either way.
  • Four projects become two. CustomNamingPolicy.NET8 (the built-in-policy demo) and CustomNamingPolicy.NET8.Test (its four tests) merge into CustomNamingPolicy and Test, and the solution loses their two entries. The split existed only because the .NET 8 policies would not compile on net7; at net10.0 that reason is gone. CustomNamingPolicy.NET8.Test.csproj carried no ProjectReference at all - its tests exercise JsonNamingPolicy statics from the BCL - so nothing depended on the removed projects.
  • Test packages to current stable (NuGet, read at prep time): NUnit 4.6.1, NUnit3TestAdapter 6.3.0, NUnit.Analyzers 4.14.0, Microsoft.NET.Test.Sdk 18.9.0, coverlet.collector 10.0.1. The seven Assert.AreEqual calls move to Assert.That(actual, Is.EqualTo(expected)).
  • Program.cs converts to top-level statements, matching the article's snippets and removing a class that shared its name with its namespace.
  • Two idiom lifts, both in code the article prints: ArgumentNullException.ThrowIfNull(name) in NodeSeparatorPolicy, and name[1..] in CamelCasePolicy. Both land in the article's code blocks in the same edit.
  • Person.surName is left exactly as it is on purpose. The deliberately lower-cased property is the article's demonstration that the serializer copies member names verbatim.

Verification

SDK 10.0.302, runtime 10.0.10.

  • dotnet build -c Release: 0 errors, 0 warnings.
  • dotnet test -c Release: 7/7 passing (3 existing plus the 4 moved).
  • dotnet run prints, in order:
{"GivenName":"Name1","surName":"Surname1"}
{"givenName":"Name1","surName":"Surname1"}
{"given/name":"Name1","sur/name":"Surname1"}
{"property_name":"value"}
{"PROPERTY_NAME":"value"}
{"property-name":"value"}
{"PROPERTY-NAME":"value"}

Every output string quoted in the article matches this run.

…two, NUnit 4

- Both surviving projects move from net7 to net10.0.
- The .NET8 sample and its four tests merge into CustomNamingPolicy and Test;
  both .NET8 projects are deleted and the solution loses their entries. The
  split only existed because the .NET 8 policies would not compile on net7.
  CustomNamingPolicy.NET8.Test had no ProjectReference, so nothing depended on
  the removed projects.
- Test packages to current stable: NUnit 4.6.1, NUnit3TestAdapter 6.3.0,
  NUnit.Analyzers 4.14.0, Microsoft.NET.Test.Sdk 18.9.0, coverlet.collector
  10.0.1. The seven assertions move to Assert.That(..., Is.EqualTo(...)).
- Program.cs converts to top-level statements, which also removes a class that
  shared its name with its namespace.
- NodeSeparatorPolicy uses ArgumentNullException.ThrowIfNull and
  CamelCasePolicy uses a range indexer; both land in the article's snippets.

Build: 0 warnings, 0 errors. Tests: 7/7 passing. 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