style: idiomatic cleanups in AsYouTypeFormatter and PhoneNumberMatcher - #416
Merged
Conversation
- string.Equals(string) -> == / != (idiomatic C#; Java's port required .equals() since Java lacks operator overloading for strings) - MinLeadingDigitsLength: static readonly int -> const int (matches Java's static final int, and the file's other true constants) - Make StringBuilder-to-string concatenation explicit with .ToString() instead of relying on the compiler's implicit ToString() via the string + object overload - Match the file's dominant Allman brace style in a couple of spots that had drifted to K&R - Drop a stray double blank line
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #416 +/- ##
==========================================
+ Coverage 87.42% 87.43% +0.01%
==========================================
Files 41 41
Lines 3856 3852 -4
Branches 990 991 +1
==========================================
- Hits 3371 3368 -3
+ Misses 283 282 -1
Partials 202 202 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
📊 Benchmark Results
PR branch
PR base
|
CodeQL flagged the two spots where this PR added explicit .ToString() on prefixBeforeNationalNumber: the other operand in each expression is already a string, so the compiler's string+object overload calls ToString() implicitly anyway. Revert those two to the implicit form — also more consistent with the PR's own idiomatic-cleanup goal. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Aug 26, 2026
This was referenced Aug 28, 2026
Closed
Closed
Merged
This was referenced Sep 7, 2026
Closed
Open
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
Part of an ongoing sweep bringing every C# file up to more idiomatic C# conventions (same spirit as #409), without straying from the Java source's method structure.
string.Equals(string)->==/!=in both files (the Java source needs.equals()since Java has no operator overloading for strings; the direct port carried that over unnecessarily).AsYouTypeFormatter.MinLeadingDigitsLength:static readonly int->const int(it mirrors Java'sstatic final int MIN_LEADING_DIGITS_LENGTH = 3, a true compile-time constant, and matches the file's otherconstfields).AsYouTypeFormatter: made a couple ofStringBuilder + stringconcatenations use explicit.ToString()instead of relying on the compiler's implicitToString()call via thestring operator +(object, string)overload — same behavior, clearer intent.PhoneNumberMatcher: fixed a couple of spots that had drifted to K&R brace style to match the file's dominant Allman style; dropped a stray double blank line inAsYouTypeFormatter.No behavior changes. Not touching the Java-parity fixes from #408 in these same two files.
Test plan
dotnet build csharp/PhoneNumbers.slnx— clean, 0 warnings (TreatWarningsAsErrors)dotnet test csharp/PhoneNumbers.Test/PhoneNumbers.Test.csproj— 414/414 passing on net8.0 and net10.0