ArgumentAssert 1.0.0

.NET 6.0
NuGet\Install-Package ArgumentAssert -Version 1.0.0
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.
dotnet add package ArgumentAssert --version 1.0.0
<PackageReference Include="ArgumentAssert" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ArgumentAssert --version 1.0.0
#r "nuget: ArgumentAssert, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install ArgumentAssert as a Cake Addin
#addin nuget:?package=ArgumentAssert&version=1.0.0

// Install ArgumentAssert as a Cake Tool
#tool nuget:?package=ArgumentAssert&version=1.0.0

ArgumentAssert

Overview

ArgumentAssert is a library that simplifies asserting conditions on arguments. If the condition is not met, an ArgumentAssertException is thrown with a description of the failed check. In addition, the Assert() method informs code-analysis that the check must have been true if execution continues.

Add the following package reference to include ArgumentAssert package in your project.

<PackageReference Include="ArgumentAssert" Version="1.0.0" />

Sample: Assertion throws exception

The following code asserts the value argument is within the expected range or throws an ArgumentAssertException exception.

int AssertValueIsInRange(int value) {
    ArgumentAssertException.Assert(value is > 0 and < 10);
    return value;
}

When the assertion fails, the exception message shows the failed expression.

Unhandled exception. System.ArgumentAssertException: value is > 0 and < 10

Sample: Assertion informs code analysis

The following code asserts the value argument is not null. Code analysis knows that the pattern is true when Assert() returns successfully. Therefore, there is no warning for the return statement.

string AssertValueIsNotNull(string? value) {
    ArgumentAssertException.Assert(value is not null);

    // no warning on the following line
    return value.ToUpper();
}

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 109 2/15/2022