EnsureFramework 1.3.1
See the version list below for details.
dotnet add package EnsureFramework --version 1.3.1
NuGet\Install-Package EnsureFramework -Version 1.3.1
<PackageReference Include="EnsureFramework" Version="1.3.1" />
paket add EnsureFramework --version 1.3.1
#r "nuget: EnsureFramework, 1.3.1"
// Install EnsureFramework as a Cake Addin #addin nuget:?package=EnsureFramework&version=1.3.1 // Install EnsureFramework as a Cake Tool #tool nuget:?package=EnsureFramework&version=1.3.1
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.
101
- Add the namespace
namespace EnsureFramework;
- Ensure things!
argument-string method
... or you can use expressions...public void MyMethod(string anArgument) { Ensure.Arg(anArgument, nameof(anArgument)).IsNotNullOrEmpty(); }
expression based methodpublic void MyMethod(string anArgument) { Ensure.Arg(() => anArgument).IsNotNullOrEmpty(); }
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
- IEnumerable
- Guid
- Object
- String
- Int32/int
- IDictionary
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<string> IsNotNullOrEmpty(this IArgumentAssertionBuilder<string> @this)
{
if (@this.Argument == null)
{
throw new ArgumentNullException(@this.ArgumentName);
}
if (@this.Argument == string.Empty)
{
throw new ArgumentException(null, @this.ArgumentName);
}
return @this;
}
Check out the code and tests (or lack-there-of) for a bit more info - the project is quite simple.
Product | Versions 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 was computed. 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 is compatible. netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.6 is compatible. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 is compatible. 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 | tizen30 was computed. 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. |
-
.NETCoreApp 1.1
- Microsoft.NETCore.App (>= 1.1.2)
-
.NETCoreApp 2.0
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETStandard 1.6
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.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.