style: idiomatic cleanups in PhoneNumberUtil platform partials - #417
Merged
Conversation
…orm partials Replace == null / != null with is null / is not null pattern matching (no operator overloads on the affected types, so behavior is identical), and use ArgumentNullException.ThrowIfNull in the net8.0/net10.0 half where the BCL helper is available. The netstandard2.0 half keeps the manual throw since ThrowIfNull isn't part of that target's API surface.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #417 +/- ##
==========================================
+ Coverage 87.42% 87.48% +0.06%
==========================================
Files 41 41
Lines 3856 3852 -4
Branches 990 990
==========================================
- Hits 3371 3370 -1
+ Misses 283 281 -2
+ Partials 202 201 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
📊 Benchmark Results
PR branch
PR base
|
…tadata Upstream Java gates this branch on metadataForRegionCallingFrom != null before dereferencing it; the C# port had swapped that for IsValidRegionCode(regionCallingFrom), a different condition that can diverge from actual metadata resolution (e.g. under a custom IMetadataLoader with gaps), leaving the dereference on the next line unguarded. Ported the null check faithfully in both TFM halves (net.cs and netstandard.cs share the same logic). Flagged by CodeQL (cs/dereferenced-value-may-be-null, alert #244) on the netstandard.cs side. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2 tasks
This was referenced Aug 28, 2026
Closed
Open
Merged
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.
Summary
Small idiomatic-C# readability pass over the two platform-specific halves of the
PhoneNumberUtilpartial class — part of the broader file-by-file cleanup sweep (see #409). Not fixing bugs, not chasing Java parity (these two files are this port's own platform-conditional compilation split, with no single Java equivalent), not restructuring logic.PhoneNumberUtil.net.cs(net8.0/net10.0 half):== null/!= null→is null/is not nullpattern matching throughout; the leadingif (number == null) throw new ArgumentNullException(...)inFormatreplaced withArgumentNullException.ThrowIfNull(number), available since this half only ever compiles under NET5_0_OR_GREATER in this repo's actual TFM set (netstandard2.0/net8.0/net10.0).PhoneNumbers/PhoneNumberUtil.netstandard.cs(netstandard2.0 half): sameis null/is not nullconversions; kept the manualif (number is null) throw ...sinceArgumentNullException.ThrowIfNullisn't part of netstandard2.0's API surface.Verified no operator
==/!=overloads exist on the affected types (PhoneNumber,NumberFormat), sois null/is not nullis behavior-identical to the reference-equality==/!=it replaces.Test plan
dotnet build csharp/PhoneNumbers.slnx— clean build, 0 warnings (TreatWarningsAsErrors), all three TFMs (netstandard2.0, net8.0, net10.0)dotnet test csharp/PhoneNumbers.Test/PhoneNumbers.Test.csproj— 414/414 passing on net8.0 and net10.0