Skip to content

Modernize C# patterns and eliminate inconsistencies#429

Merged
sensslen merged 5 commits intomainfrom
copilot/investigate-code-inconsistencies
Feb 10, 2026
Merged

Modernize C# patterns and eliminate inconsistencies#429
sensslen merged 5 commits intomainfrom
copilot/investigate-code-inconsistencies

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 9, 2026

Codebase contained inconsistent patterns (old-style null checks, string concatenation, verbose initializations) deviating from modern C# conventions.

Changes

Null check pattern modernization

  • Replaced == null/!= null with is null/is not null across 14 instances
  • Updated: CommandLineOptionsParser.cs, LicenseValidator.cs, PackageInformationReader.cs, CachingDisposableSourceRepository.cs

Before:

if (licenseMapping == null) { ... }
if (metadata != null) { ... }

After:

if (licenseMapping is null) { ... }
if (metadata is not null) { ... }

String handling improvements

  • Converted concatenation to interpolation in StringExtensions.cs, LicenseValidator.cs, LicenseValidationResult.cs

Before:

"^" + Regex.Escape(pattern).Replace(@"\*", ".*") + "$"
new Uri(licenseUrl.ToString() + "?raw=true")

After:

$"^{Regex.Escape(pattern).Replace(@"\*", ".*")}$"
new Uri($"{licenseUrl}?raw=true")

Field initialization modernization

  • Updated verbose initializers to target-typed new() in 5 files

Before:

private readonly List<string[][]> _rows = new List<string[][]>();
private readonly SemaphoreSlim _limiter = new SemaphoreSlim(10, 10);

After:

private readonly List<string[][]> _rows = new();
private readonly SemaphoreSlim _limiter = new(10, 10);

Exclusions

SPDX code (Java port) deliberately untouched to maintain upstream alignment.

Impact

9 files modified, ~50 lines simplified. Zero functionality changes - all tests pass.

Original prompt

Investigate inconsistencies in the code and also shortcomings (where suboptimal patterns are followed) and fix those. Be sure to not alter any functionality.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 9, 2026 13:00
Co-authored-by: sensslen <3428860+sensslen@users.noreply.github.com>
…ield initialization

Co-authored-by: sensslen <3428860+sensslen@users.noreply.github.com>
Co-authored-by: sensslen <3428860+sensslen@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix inconsistencies and suboptimal patterns in code Modernize C# patterns and eliminate inconsistencies Feb 9, 2026
Copilot AI requested a review from sensslen February 9, 2026 13:20
Comment thread src/NuGetLicense/LicenseValidator/LicenseValidator.cs Outdated
… clarity

Co-authored-by: sensslen <3428860+sensslen@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

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.

2 participants