NetEvolve.Arguments 2.0.17

Prefix Reserved
dotnet add package NetEvolve.Arguments --version 2.0.17
                    
NuGet\Install-Package NetEvolve.Arguments -Version 2.0.17
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetEvolve.Arguments" Version="2.0.17" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetEvolve.Arguments" Version="2.0.17" />
                    
Directory.Packages.props
<PackageReference Include="NetEvolve.Arguments" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NetEvolve.Arguments --version 2.0.17
                    
#r "nuget: NetEvolve.Arguments, 2.0.17"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NetEvolve.Arguments@2.0.17
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NetEvolve.Arguments&version=2.0.17
                    
Install as a Cake Addin
#tool nuget:?package=NetEvolve.Arguments&version=2.0.17
                    
Install as a Cake Tool

NetEvolve.Arguments

License Build Status

A comprehensive library providing backward-compatible argument validation helper methods (ThrowIf*) for .NET projects targeting multiple framework versions. This library enables modern argument validation patterns across legacy and current .NET runtimes, ensuring code consistency and maintainability.

Overview

Modern .NET versions (starting with .NET 6) introduced streamlined argument validation methods such as ArgumentNullException.ThrowIfNull and ArgumentOutOfRangeException.ThrowIfEqual. However, projects targeting multiple frameworks or older .NET versions cannot utilize these convenient methods without conditional compilation or duplicated validation logic.

NetEvolve.Arguments bridges this gap by providing polyfilled implementations of these modern validation methods, allowing developers to write consistent, maintainable argument validation code regardless of the target framework.

Key Features

  • Multi-Framework Support: Compatible with .NET Standard 2.0, .NET 8.0, .NET 9.0, and .NET 10.0
  • Zero Runtime Overhead: Uses conditional compilation to delegate to native implementations where available
  • Drop-in Replacement: Identical API signatures to native .NET implementations
  • Type-Safe: Fully generic implementations with proper type constraints
  • Comprehensive Coverage: Includes null checks, range validations, and equality comparisons

Installation

Install the package via NuGet Package Manager:

dotnet add package NetEvolve.Arguments

Or via the Package Manager Console:

Install-Package NetEvolve.Arguments

Usage

Import the namespace in your code:

using NetEvolve.Arguments;

Then use the validation methods just as you would with native .NET implementations:

public void ProcessData(string data, int count)
{
    Argument.ThrowIfNullOrWhiteSpace(data);
    Argument.ThrowIfLessThan(count, 1);
    
    // Your implementation
}

Available Methods

Null Validation

Argument.ThrowIfNull(object?, string?)

Throws an ArgumentNullException if the argument is null.

Replacement for: ArgumentNullException.ThrowIfNull(object, string) (introduced in .NET 6)

Example:

public void Process(object data)
{
    Argument.ThrowIfNull(data);
}
Argument.ThrowIfNull(void*, string?)

Throws an ArgumentNullException if the pointer argument is null.

Replacement for: ArgumentNullException.ThrowIfNull(void*, string) (introduced in .NET 7)

Argument.ThrowIfNullOrEmpty(string?, string?)

Throws an ArgumentNullException if the argument is null, or an ArgumentException if the argument is an empty string.

Replacement for: ArgumentException.ThrowIfNullOrEmpty(string, string) (introduced in .NET 7)

Example:

public void Process(string name)
{
    Argument.ThrowIfNullOrEmpty(name);
}
Argument.ThrowIfNullOrEmpty<T>(IEnumerable<T>?, string?)

Throws an ArgumentNullException if the argument is null, or an ArgumentException if the collection is empty.

Note: This is a custom extension method not present in the base .NET framework, providing convenient collection validation.

Example:

public void Process(IEnumerable<int> items)
{
    Argument.ThrowIfNullOrEmpty(items);
}
Argument.ThrowIfNullOrWhiteSpace(string?, string?)

Throws an ArgumentNullException if the argument is null, or an ArgumentException if the argument is empty or contains only white-space characters.

Replacement for: ArgumentException.ThrowIfNullOrWhiteSpace(string, string) (introduced in .NET 8)

Example:

public void Process(string description)
{
    Argument.ThrowIfNullOrWhiteSpace(description);
}

Range Validation

Argument.ThrowIfEqual<T>(T, T, string?)

Throws an ArgumentOutOfRangeException if the first argument is equal to the second argument.

Replacement for: ArgumentOutOfRangeException.ThrowIfEqual<T>(T, T, string) (introduced in .NET 8)

Example:

public void SetValue(int value)
{
    Argument.ThrowIfEqual(value, 0); // Value must not be zero
}
Argument.ThrowIfNotEqual<T>(T, T, string?)

Throws an ArgumentOutOfRangeException if the first argument is not equal to the second argument.

Replacement for: ArgumentOutOfRangeException.ThrowIfNotEqual<T>(T, T, string) (introduced in .NET 8)

Argument.ThrowIfGreaterThan<T>(T, T, string?)

Throws an ArgumentOutOfRangeException if the first argument is greater than the second argument.

Replacement for: ArgumentOutOfRangeException.ThrowIfGreaterThan<T>(T, T, string) (introduced in .NET 8)

Example:

public void SetAge(int age)
{
    Argument.ThrowIfGreaterThan(age, 150); // Age must be 150 or less
}
Argument.ThrowIfGreaterThanOrEqual<T>(T, T, string?)

Throws an ArgumentOutOfRangeException if the first argument is greater than or equal to the second argument.

Replacement for: ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual<T>(T, T, string) (introduced in .NET 8)

Example:

public void SetCount(int count, int maximum)
{
    Argument.ThrowIfGreaterThanOrEqual(count, maximum); // Count must be less than maximum
}
Argument.ThrowIfLessThan<T>(T, T, string?)

Throws an ArgumentOutOfRangeException if the first argument is less than the second argument.

Replacement for: ArgumentOutOfRangeException.ThrowIfLessThan<T>(T, T, string) (introduced in .NET 8)

Example:

public void SetCount(int count)
{
    Argument.ThrowIfLessThan(count, 1); // Count must be at least 1
}
Argument.ThrowIfLessThanOrEqual<T>(T, T, string?)

Throws an ArgumentOutOfRangeException if the first argument is less than or equal to the second argument.

Replacement for: ArgumentOutOfRangeException.ThrowIfLessThanOrEqual<T>(T, T, string) (introduced in .NET 8)

Example:

public void SetMinimum(int value, int threshold)
{
    Argument.ThrowIfLessThanOrEqual(value, threshold); // Value must be greater than threshold
}

Framework Compatibility

Target Framework Status Notes
.NET Standard 2.0 ✅ Supported Full polyfill implementations
.NET 8.0 ✅ Supported Delegates to native implementations where available
.NET 9.0 ✅ Supported Full native delegation
.NET 10.0 ✅ Supported Full native delegation

Contributing

Contributions are welcome! Please feel free to submit issues, fork the repository, and create pull requests.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on NetEvolve.Arguments:

Package Downloads
NetEvolve.Extensions.Tasks

This library provides simple extension methods for `Task`, `Task<T>`, `ValueTask` and `ValueTask<T>`.

NetEvolve.Guard

Basic input validation via the `Ensure`-class throws an `ArgumentException`, `ArgumentNullException` or other Exception types, if the conditions are not met. The second parameter `parameterName` from `Ensure.That(T value, string? parameterName = default!)` is optional and is automatically populated by .NET, based on the `CallerArgumentExpressionAttribute` functionality.

NetEvolve.Extensions.Strings

Library with common `string` extension methods for easy reuse.

NetEvolve.Logging.XUnit

Extensions for `ILogger` implementations to log messages to xUnit test output.

NetEvolve.FluentValue

The fluent value validation library provides a set of fluent interfaces to validate values.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.17 1,164 11/30/2025
2.0.0 3,397 11/20/2025
1.3.134 3,042 10/22/2025
1.3.84 9,605 5/5/2025
1.3.77 507 5/1/2025
1.3.68 12,648 4/8/2025
1.3.43 5,540 2/2/2025
1.3.37 1,263 1/29/2025
1.3.0 5,291 12/16/2024
1.2.168 3,946 11/28/2024
1.2.100 7,184 9/11/2024
1.2.90 1,211 8/26/2024
1.2.50 5,566 6/23/2024
1.2.46 420 6/18/2024
1.2.12 5,833 5/21/2024
1.2.11 193 5/21/2024
1.2.0 309 4/26/2024
1.1.9 1,709 4/8/2024
1.1.3 1,676 4/5/2024
1.1.0 298 4/4/2024
1.0.123 3,182 2/17/2024
1.0.88 4,144 1/3/2024
1.0.65 5,236 11/17/2023
1.0.58 1,042 11/15/2023
1.0.8 3,937 8/29/2023
1.0.6 381 8/29/2023
1.0.5 582 8/28/2023