EnsureFramework 2.0.0-alpha
See the version list below for details.
dotnet add package EnsureFramework --version 2.0.0-alpha
NuGet\Install-Package EnsureFramework -Version 2.0.0-alpha
<PackageReference Include="EnsureFramework" Version="2.0.0-alpha" />
<PackageVersion Include="EnsureFramework" Version="2.0.0-alpha" />
<PackageReference Include="EnsureFramework" />
paket add EnsureFramework --version 2.0.0-alpha
#r "nuget: EnsureFramework, 2.0.0-alpha"
#:package EnsureFramework@2.0.0-alpha
#addin nuget:?package=EnsureFramework&version=2.0.0-alpha&prerelease
#tool nuget:?package=EnsureFramework&version=2.0.0-alpha&prerelease
EnsureFramework
EnsureFramework is designed to take the pain out of null checking and making sure (ensuring) your methods are being used the way they were intended and throwing exceptions when unsupported values are passed to them.
You can make sure values are in a specific range or simply make sure that an argument is not null.
It was designed to be readable and fluent based, meaning you can chain ensurables together and the first one that fails will result in the exception.
Ensuring implicitly checks for null so there is no need to have a .IsNull() call. So if you want to
ensure it is not null, you can just Ensure.Arg(myArg).
101
- Add the namespace
namespace EnsureFramework; - Ensure things!
public void MyMethod(string anArgument) { Ensure.Arg(anArgument).IsNotEmpty(); }
Other things
You can ensure your arguments directly using the argument-string override or with the expression override. You need to be aware that if performance is desired the argument-string override is the best.
Supported types
There are extensions for common types in .NET but not much else outside of that. We support:
- IComparable ⫽ for example...
- System.Decimal
- System.Enum
- System.String
- System.DateTime
- System.Boolean
- System.Byte
- System.Char
- System.DateTimeOffset
- System.Double
- System.Guid
- System.Int16
- System.Int32
- System.Int64
- System.SByte
- System.Single
- System.TimeSpan
- System.Tuple<T1>
- System.Tuple<T1,T2>
- System.Tuple<T1,T2,T3>
- System.Tuple<T1,T2,T3,T4>
- System.Tuple<T1,T2,T3,T4,T5>
- System.Tuple<T1,T2,T3,T4,T5,T6>
- System.Tuple<T1,T2,T3,T4,T5,T6,T7>
- System.Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>
- System.UInt16
- System.UInt32
- System.UInt64
- System.ValueTuple
- System.ValueTuple<T1>
- System.ValueTuple<T1,T2>
- System.ValueTuple<T1,T2,T3>
- System.ValueTuple<T1,T2,T3,T4>
- System.ValueTuple<T1,T2,T3,T4,T5>
- System.ValueTuple<T1,T2,T3,T4,T5,T6>
- System.ValueTuple<T1,T2,T3,T4,T5,T6,T7>
- System.ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest>
- System.Version
- IEnumerable
- List
- Collection
- Dictionary
- Dictionary
- Guid
- Int32/int
- Object
- String
Well Mike, my type isn't supported...
That's cool friend, just create your own by adding extension methods to your project. Here is a simple one that should point you in the right direction:
public static IArgumentAssertionBuilder<User> IsAnAdult(this IArgumentAssertionBuilder<User> @this)
{
if (@this.Argument.DateOfBirth >= DateTime.Today.AddYears(-18))
{
throw new ArgumentException("User is underage", @this.ArgumentName);
}
return @this;
}
Check out the code and tests for a bit more info - the project is quite simple.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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 was computed. 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. |
-
net8.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 |
|---|---|---|
| 2.0.3-alpha | 56 | 6/2/2026 |
| 2.0.2-alpha | 60 | 6/2/2026 |
| 2.0.1-alpha | 54 | 5/15/2026 |
| 2.0.0-alpha | 61 | 5/15/2026 |
| 1.3.2 | 1,899 | 10/22/2019 |
| 1.3.1 | 940 | 7/23/2019 |
| 1.3.0 | 926 | 5/27/2019 |
| 1.2.1 | 1,985 | 7/4/2018 |
| 1.2.0 | 1,647 | 6/15/2018 |
| 1.1.0 | 1,665 | 4/16/2018 |
| 1.0.0 | 1,841 | 8/30/2016 |