Add polyfills for ArgumentNullException.ThrowIfNull(...), ArgumentException.ThrowIfNullOrEmpty(...) and ArgumentException.ThrowIfNullOrWhiteSpace(...)#37
Merged
Conversation
…Exception.ThrowIfNullOrEmpty(...)` and `ArgumentException.ThrowIfNullOrWhiteSpace(...)`
Contributor
There was a problem hiding this comment.
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.ThrowIfNullpolyfill for .NET versions prior to 6.0 - Added
ArgumentException.ThrowIfNullOrEmptyandArgumentException.ThrowIfNullOrWhiteSpacepolyfills 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This was referenced Dec 1, 2025
This was referenced Jan 1, 2026
This was referenced Feb 1, 2026
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.
No description provided.