Skip to content

Add polyfills for ArgumentNullException.ThrowIfNull(...), ArgumentException.ThrowIfNullOrEmpty(...) and ArgumentException.ThrowIfNullOrWhiteSpace(...)#37

Merged
Tyrrrz merged 3 commits into
masterfrom
ane-throwifnull
Nov 16, 2025
Merged

Conversation

@Tyrrrz

@Tyrrrz Tyrrrz commented Nov 16, 2025

Copy link
Copy Markdown
Owner

No description provided.

…Exception.ThrowIfNullOrEmpty(...)` and `ArgumentException.ThrowIfNullOrWhiteSpace(...)`
Copilot AI review requested due to automatic review settings November 16, 2025 16:25
@Tyrrrz Tyrrrz added the enhancement New feature or request label Nov 16, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds polyfills for three argument validation helper methods introduced in .NET 6.0 and .NET 7.0: ArgumentNullException.ThrowIfNull, ArgumentException.ThrowIfNullOrEmpty, and ArgumentException.ThrowIfNullOrWhiteSpace. These polyfills enable projects targeting older .NET versions to use these modern convenience methods for argument validation.

Key changes:

  • Added ArgumentNullException.ThrowIfNull polyfill for .NET versions prior to 6.0
  • Added ArgumentException.ThrowIfNullOrEmpty and ArgumentException.ThrowIfNullOrWhiteSpace polyfills for .NET versions prior to 7.0
  • Comprehensive test coverage for all three methods verifying correct exception types and parameter names

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
PolyShim/Net60/ArgumentNullException.cs Implements ThrowIfNull static method polyfill for .NET < 6.0, using CallerArgumentExpression to capture parameter names
PolyShim/Net70/ArgumentException.cs Implements ThrowIfNullOrEmpty and ThrowIfNullOrWhiteSpace static method polyfills for .NET < 7.0, with proper null vs empty/whitespace exception handling
PolyShim.Tests/Net60/ArgumentNullExceptionTests.cs Tests ThrowIfNull with null and non-null values, verifying correct exception and parameter name capture
PolyShim.Tests/Net70/ArgumentExceptionTests.cs Tests both ThrowIfNullOrEmpty and ThrowIfNullOrWhiteSpace with appropriate test cases for null, empty/whitespace, and valid values

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PolyShim/Net70/ArgumentException.cs Outdated
Comment thread PolyShim/Net70/ArgumentException.cs Outdated
Tyrrrz and others added 2 commits November 16, 2025 18:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants