![]() |
VOOZH | about |
dotnet add package NetEvolve.Arguments --version 3.2.178
NuGet\Install-Package NetEvolve.Arguments -Version 3.2.178
<PackageReference Include="NetEvolve.Arguments" Version="3.2.178" />
<PackageVersion Include="NetEvolve.Arguments" Version="3.2.178" />Directory.Packages.props
<PackageReference Include="NetEvolve.Arguments" />Project file
paket add NetEvolve.Arguments --version 3.2.178
#r "nuget: NetEvolve.Arguments, 3.2.178"
#:package NetEvolve.Arguments@3.2.178
#addin nuget:?package=NetEvolve.Arguments&version=3.2.178Install as a Cake Addin
#tool nuget:?package=NetEvolve.Arguments&version=3.2.178Install as a Cake Tool
👁 NuGet Version
👁 NuGet Downloads
👁 License
A universal polyfill library that provides modern ArgumentNullException.ThrowIf* and ArgumentException.ThrowIf* helper methods across all .NET runtimes (.NET Standard 2.0+, .NET Framework 4.7.2+, .NET 6.0+), enabling consistent argument validation patterns regardless of target framework version.
Install-Package NetEvolve.Arguments
dotnet add package NetEvolve.Arguments
<PackageReference Include="NetEvolve.Arguments" />
using NetEvolve.Arguments;
public class UserService
{
public void CreateUser(string username, string email, int age)
{
// Validate arguments with modern .NET 8+ API - works on all frameworks!
ArgumentException.ThrowIfNullOrWhiteSpace(username);
ArgumentException.ThrowIfNullOrWhiteSpace(email);
ArgumentOutOfRangeException.ThrowIfNegative(age);
ArgumentOutOfRangeException.ThrowIfGreaterThan(age, 150);
// Your logic here
}
}
NetEvolve.Arguments brings modern .NET 8+ argument validation APIs to older framework versions. This means:
This allows you to write code once using modern patterns and have it work consistently across all supported frameworks.
Validates that a reference or pointer is not null.
public void ProcessData(object data)
{
ArgumentNullException.ThrowIfNull(data);
// data is guaranteed non-null here
}
// With unsafe pointers (requires unsafe context)
public unsafe void ProcessPointer(void* ptr)
{
ArgumentNullException.ThrowIfNull(ptr);
// ptr is guaranteed non-null here
}
Validates that a string is neither null nor empty.
public void SetUsername(string username)
{
ArgumentException.ThrowIfNullOrEmpty(username);
// username is guaranteed to have at least one character
}
Validates that a string is not null, empty, or whitespace-only.
public void SetDescription(string description)
{
ArgumentException.ThrowIfNullOrWhiteSpace(description);
// description is guaranteed to have non-whitespace content
}
Validates that a string does not exceed a maximum length.
public void SetTitle(string title)
{
ArgumentException.ThrowIfLengthGreaterThan(title, 100);
// title is guaranteed to be 100 characters or less
}
Validates that a string meets a minimum length requirement.
public void SetPassword(string password)
{
ArgumentException.ThrowIfLengthLessThan(password, 8);
// password is guaranteed to be at least 8 characters
}
Validates that a string length falls within a specified range.
public void SetPostalCode(string postalCode)
{
ArgumentException.ThrowIfLengthOutOfRange(postalCode, 5, 10);
// postalCode length is between 5 and 10 characters
}
Validates that a string does not contain any whitespace characters.
public void SetIdentifier(string identifier)
{
ArgumentException.ThrowIfContainsWhiteSpace(identifier);
// identifier is guaranteed to have no spaces, tabs, or other whitespace
}
Validates that a collection is neither null nor empty. Supports multiple collection types.
// IEnumerable<T>
public void ProcessItems(IEnumerable<string> items)
{
ArgumentException.ThrowIfNullOrEmpty(items);
// items is guaranteed to have at least one element
}
// ICollection<T>
public void ProcessList(ICollection<int> numbers)
{
ArgumentException.ThrowIfNullOrEmpty(numbers);
}
// IReadOnlyCollection<T>
public void ProcessReadOnly(IReadOnlyCollection<string> values)
{
ArgumentException.ThrowIfNullOrEmpty(values);
}
// Arrays
public void ProcessArray(string[] items)
{
ArgumentException.ThrowIfNullOrEmpty(items);
}
Validates that a collection does not exceed a maximum count.
public void ProcessBatch(ICollection<Order> orders)
{
ArgumentException.ThrowIfCountGreaterThan(orders, 1000);
// orders collection has at most 1000 items
}
Validates that a collection meets a minimum count requirement.
public void ProcessTeam(IEnumerable<User> users)
{
ArgumentException.ThrowIfCountLessThan(users, 2);
// users collection has at least 2 members
}
Validates that a collection count falls within a specified range.
public void ProcessGroup(IReadOnlyCollection<Person> people)
{
ArgumentException.ThrowIfCountOutOfRange(people, 3, 10);
// people collection has between 3 and 10 members
}
Validates that a collection does not contain duplicate elements.
public void ProcessUniqueIds(IEnumerable<int> ids)
{
ArgumentException.ThrowIfContainsDuplicates(ids);
// ids collection contains only unique values
}
// With custom comparer
public void ProcessUniqueNames(IEnumerable<string> names)
{
ArgumentException.ThrowIfContainsDuplicates(names, StringComparer.OrdinalIgnoreCase);
// names collection contains unique values (case-insensitive)
}
Validates that a numeric value is not zero.
public void SetDivisor(int divisor)
{
ArgumentOutOfRangeException.ThrowIfZero(divisor);
// divisor is guaranteed to be non-zero
}
Validates that a numeric value is not negative.
public void SetQuantity(int quantity)
{
ArgumentOutOfRangeException.ThrowIfNegative(quantity);
// quantity is guaranteed to be >= 0
}
// Works with nint on older frameworks
public void SetNativeInt(nint value)
{
ArgumentOutOfRangeException.ThrowIfNegative(value);
}
Validates that a numeric value is positive (greater than zero).
public void SetPrice(decimal price)
{
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(price);
// price is guaranteed to be > 0
}
Validates that a value is not equal to a specified value.
public void SetStatus(int status)
{
ArgumentOutOfRangeException.ThrowIfEqual(status, 0);
// status is guaranteed to be non-zero
}
Validates that a value equals a specified value.
public void ProcessExpectedValue(int actual, int expected)
{
ArgumentOutOfRangeException.ThrowIfNotEqual(actual, expected);
// actual is guaranteed to equal expected
}
Validates that a value does not exceed a maximum.
public void SetPercentage(int percentage)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(percentage, 100);
// percentage is guaranteed to be <= 100
}
Validates that a value is strictly less than a maximum.
public void SetIndex(int index, int arrayLength)
{
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, arrayLength);
// index is guaranteed to be < arrayLength (valid array index)
}
Validates that a value meets a minimum requirement.
public void SetAge(int age)
{
ArgumentOutOfRangeException.ThrowIfLessThan(age, 18);
// age is guaranteed to be >= 18
}
Validates that a value is strictly greater than a minimum.
public void SetRating(int rating)
{
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(rating, 0);
// rating is guaranteed to be > 0
}
Validates that a value falls within a specified range (inclusive).
public void SetVolume(int volume)
{
ArgumentOutOfRangeException.ThrowIfOutOfRange(volume, 0, 100);
// volume is guaranteed to be between 0 and 100 (inclusive)
}
These methods are available on .NET 8.0+ only, providing validation for temporal values.
Validates that a DateTimeOffset is not in the past.
public void ScheduleEvent(DateTimeOffset eventTime)
{
ArgumentOutOfRangeException.ThrowIfInPast(eventTime);
// eventTime is guaranteed to be >= current UTC time
}
// With custom TimeProvider for testing
public void ScheduleEvent(DateTimeOffset eventTime, TimeProvider timeProvider)
{
ArgumentOutOfRangeException.ThrowIfInPast(eventTime, timeProvider);
}
Validates that a DateTimeOffset is not in the future.
public void RecordTransaction(DateTimeOffset timestamp)
{
ArgumentOutOfRangeException.ThrowIfInFuture(timestamp);
// timestamp is guaranteed to be <= current UTC time
}
Validates that a DateTime is not in the past.
public void ScheduleAppointment(DateTime appointmentTime)
{
ArgumentOutOfRangeException.ThrowIfInPast(appointmentTime);
// appointmentTime is guaranteed to be >= current UTC time
}
Validates that a DateTime is not in the future.
public void LogActivity(DateTime activityTime)
{
ArgumentOutOfRangeException.ThrowIfInFuture(activityTime);
// activityTime is guaranteed to be <= current UTC time
}
Validates that a DateOnly is not in the past.
public void BookEvent(DateOnly eventDate)
{
ArgumentOutOfRangeException.ThrowIfInPast(eventDate);
// eventDate is guaranteed to be >= today's date
}
Validates that a DateOnly is not in the future.
public void RecordBirthdate(DateOnly birthdate)
{
ArgumentOutOfRangeException.ThrowIfInFuture(birthdate);
// birthdate is guaranteed to be <= today's date
}
Validates that a value type is not its default value.
public void ProcessId(Guid id)
{
ArgumentException.ThrowIfDefault(id);
// id is guaranteed to not be default(Guid)
}
Validates that a GUID is not Guid.Empty.
public void SetUserId(Guid userId)
{
ArgumentException.ThrowIfEmptyGuid(userId);
// userId is guaranteed to not be Guid.Empty
}
For projects migrating from older codebases, the Argument class provides backward-compatible helper methods. These are marked as obsolete and delegate to the modern exception polyfills.
using NetEvolve.Arguments;
public void OldCodePattern(string value, int count)
{
// Obsolete but functional - redirects to ArgumentException.ThrowIfNullOrEmpty
Argument.ThrowIfNullOrEmpty(value);
// Obsolete but functional - redirects to ArgumentOutOfRangeException.ThrowIfNegative
Argument.ThrowIfNegative(count);
}
Migration Recommendation: Use the modern ArgumentNullException, ArgumentException, and ArgumentOutOfRangeException polyfill methods directly instead of the Argument class helpers.
// File: UserValidator.cs
// Target Framework: net48
using System;
public class UserValidator
{
public void ValidateUser(string email, int age, string[] roles)
{
// Modern .NET 8+ API works perfectly on .NET Framework 4.8!
ArgumentException.ThrowIfNullOrWhiteSpace(email);
ArgumentOutOfRangeException.ThrowIfLessThan(age, 0);
ArgumentOutOfRangeException.ThrowIfGreaterThan(age, 150);
ArgumentException.ThrowIfNullOrEmpty(roles);
}
}
// File: SharedLibrary.csproj
// <TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
using System;
using System.Collections.Generic;
namespace SharedLibrary
{
public class DataProcessor
{
// Same code works across all target frameworks
public void Process(IEnumerable<string> items, int batchSize)
{
ArgumentException.ThrowIfNullOrEmpty(items);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(batchSize);
ArgumentOutOfRangeException.ThrowIfGreaterThan(batchSize, 1000);
// Process items...
}
}
}
// File: EventScheduler.cs
// Target Framework: net10.0
using System;
public class EventScheduler
{
private readonly TimeProvider _timeProvider;
public EventScheduler(TimeProvider? timeProvider = null)
{
_timeProvider = timeProvider ?? TimeProvider.System;
}
public void ScheduleEvent(string title, DateTimeOffset startTime, DateTimeOffset endTime)
{
ArgumentException.ThrowIfNullOrWhiteSpace(title);
ArgumentException.ThrowIfLengthGreaterThan(title, 200);
// Date/time validation (available on .NET 8+)
ArgumentOutOfRangeException.ThrowIfInPast(startTime, _timeProvider);
ArgumentOutOfRangeException.ThrowIfInPast(endTime, _timeProvider);
// Ensure end is after start
if (endTime <= startTime)
{
throw new ArgumentException("End time must be after start time.", nameof(endTime));
}
}
}
NetEvolve.Arguments is designed with performance in mind:
[MethodImpl(MethodImplOptions.AggressiveInlining)] for minimal call overhead[StackTraceHidden] to produce cleaner exception stack tracesTryGetNonEnumeratedCount to avoid enumerating collections when possible// On .NET 8+, this has virtually zero overhead
ArgumentException.ThrowIfNullOrWhiteSpace(username);
// Equivalent to calling the built-in .NET 8 method directly
// No additional layers, no wrapper overhead
| Feature Category | .NET Framework 4.7.2-4.8.1 | .NET Standard 2.0 | .NET 6.0-7.0 | .NET 8.0+ |
|---|---|---|---|---|
| Null Validation | ✅ | ✅ | ✅ | ✅ (Framework Native) |
| String Validation | ✅ | ✅ | ✅ | ✅ (Framework Native) |
| Collection Validation | ✅ | ✅ | ✅ | ✅ |
| Numeric Range Validation | ✅ | ✅ | ✅ | ✅ (Framework Native) |
| DateTime/DateTimeOffset Validation | ❌ | ❌ | ❌ | ✅ |
| DateOnly Validation | ❌ | ❌ | ❌ | ✅ |
| Extended Collection Helpers | ✅ | ✅ | ✅ | ✅ |
| Special Type Validation | ✅ | ✅ | ✅ | ✅ |
public void ProcessNullableInt(int? value)
{
// ThrowIfNull works with nullable value types
ArgumentNullException.ThrowIfNull(value);
// After validation, value is guaranteed non-null
int actualValue = value.Value; // Safe - no NullReferenceException
}
public class Repository<T> where T : IComparable<T>
{
public void SetMinValue(T minValue, T maxValue)
{
// Generic constraints ensure compile-time safety
ArgumentOutOfRangeException.ThrowIfGreaterThan(minValue, maxValue);
}
}
public void OptimizedCollectionCheck(IEnumerable<string> items)
{
// Uses TryGetNonEnumeratedCount when possible
// Avoids full enumeration for ICollection<T>, arrays, etc.
ArgumentException.ThrowIfNullOrEmpty(items);
// Only enumerates if count cannot be determined without enumeration
}
All validation methods are stateless and thread-safe. They can be safely called from multiple threads concurrently.
public void ThreadSafeValidation(string input)
{
// Safe to call from multiple threads
ArgumentException.ThrowIfNullOrWhiteSpace(input);
}
For complete solution documentation, architecture decisions, and contributing guidelines, visit the Arguments Repository.
Contributions are welcome! Please read the Contributing Guidelines before submitting a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by the NetEvolve Team Visit us at https://www.daily-devops.net for more information about our services and solutions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 is compatible. net48 net48 is compatible. net481 net481 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
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. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.2.178 | 11,837 | 5/10/2026 |
| 3.2.128 | 2,698 | 4/5/2026 |
| 3.2.110 | 776 | 3/30/2026 |
| 3.2.84 | 9,601 | 3/22/2026 |
| 3.2.79 | 704 | 3/15/2026 |
| 3.2.0 | 4,801 | 1/27/2026 |
| 3.1.0 | 2,533 | 1/11/2026 |
| 3.0.0 | 21,216 | 12/31/2025 |
| 2.0.17 | 10,811 | 11/30/2025 |
| 2.0.0 | 8,544 | 11/20/2025 |
| 1.3.134 | 3,131 | 10/22/2025 |
| 1.3.84 | 15,092 | 5/5/2025 |
| 1.3.77 | 587 | 5/1/2025 |
| 1.3.68 | 13,653 | 4/8/2025 |
| 1.3.43 | 5,621 | 2/2/2025 |
| 1.3.37 | 1,775 | 1/29/2025 |
| 1.3.0 | 5,362 | 12/16/2024 |
| 1.2.168 | 4,027 | 11/28/2024 |
| 1.2.100 | 7,263 | 9/11/2024 |
| 1.2.90 | 1,523 | 8/26/2024 |