Forbid 1.0.4

.NET 5.0 .NET Core 3.1 .NET Standard 2.0
Install-Package Forbid -Version 1.0.4
dotnet add package Forbid --version 1.0.4
<PackageReference Include="Forbid" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Forbid --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Forbid, 1.0.4"
#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 Forbid as a Cake Addin
#addin nuget:?package=Forbid&version=1.0.4

// Install Forbid as a Cake Tool
#tool nuget:?package=Forbid&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

New Features!

Added params support for NullOrEmpty method


A simple package with extension methods to forbid some value matches,logical values or ranges in .Net

Supported Methods

  • Null (throws if input is null.)
  • NullOrEmpty (throws if string,guid or IEnumerable<T> is null or empty.)
  • NullOrWhitespace (throws if string input is null, empty or whitespace.)
  • Zero (throws if number input is zero.)
  • True (throws if boolean input is true.)
  • False (throws if boolean input is false.)
  • Range (throws if input is in provided range.)
  • Equal (throws if input is equal to provided value.)
  • NotEqual (throws if input is not equal to provided value.)
  • Positive (throws if input is positive number.)
  • PositiveOrZero (throws if input is positive number or zero.)
  • Negative (throws if input is negative number.)
  • NegativeOrZero (throws if input is negative number or zero.)
  • MoreThan (throws if input is more than provided value.)
  • MoreThanOrEqual (throws if input is more than or equal to provided value.)
  • LessThan (throws if input is less than provided value.)
  • LessThanOrEqual (throws if input is less than or equal to provided value.)
  • Any(throws if any element in input satisfies a condition.)

You can pass message or custom exception to methods.


public class TestClass
    private readonly ITestService _testService;
    private readonly int _someValue;
    public TestClass(ITestService testService,int someValue)
        _testService = Forbid.From.Null(_testService);
        _someValue = Forbid.From.NegativeOrZero(someValue);


public class TestClassWithCustomMessageOrException
    private readonly ITestService _testService;
    private readonly int _someValue;
    public TestClassWithCustomMessageOrException(ITestService testService,int someValue)
        _testService = Forbid.From.Null(_testService,"test service must not be null.");
        _someValue = Forbid.From.NegativeOrZero(someValue,new CustomException());

Or you can inject service in DI Container and use IForbid interface. for this install nuget package Forbid.Extensions.Microsoft.DependencyInjection.

using Forbids;

public void ConfigureServices(IServiceCollection services)
    services.AddForbids(); //default is Singleton, you can pass ServiceLifetime

and then

public class TestClassWithDISupport
    private readonly IForbid _forbid;
    public TestClassWithDISupport(IForbid forbid)
        _forbid = forbid;
    public void SomeForbid(int value)
        // more logic here

Extend Forbids

To extend forbids, you can do the following:

public static class TestExtend
        public static string Test(this IForbid forbid, string input,Exception exception)
            if (input == "test")
                throw exception;
            return input;
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Forbid:

Package Downloads

Dependency injection support for Forbid package.


Package to automatically inject attribute decorated services into IOC Container.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 1,415 11/4/2021
1.0.3 166 10/30/2021
1.0.2 163 10/16/2021
1.0.1 222 9/26/2021
1.0.0 1,503 9/18/2021