LiteX.Guard 2.0.0

.NET Standard 2.0
dotnet add package LiteX.Guard --version 2.0.0
NuGet\Install-Package LiteX.Guard -Version 2.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.
<PackageReference Include="LiteX.Guard" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LiteX.Guard --version 2.0.0
#r "nuget: LiteX.Guard, 2.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 LiteX.Guard as a Cake Addin
#addin nuget:?package=LiteX.Guard&version=2.0.0

// Install LiteX.Guard as a Cake Tool
#tool nuget:?package=LiteX.Guard&version=2.0.0


LiteX.Guard is a simple guard clause argument validation library, that helps you with validation of your arguments.

Install Nuget package

Run the nuget command for installing the client as,

Install-Package LiteX.Guard

Supported Guard Clauses


  • Guard.NotNull (throws if input is null)
  • Guard.NotNullOrEmpty (throws if string input is null or empty)


  • Guard.InRange (throws if specified value is greater than or equal to a minimum value and less than)
  • Guard.LessThan (throws if specified value is less than a maximum value)
  • Guard.LessThanOrEqualTo (throws if specified value is less than or equal to a maximum value)
  • Guard.GreaterThan (throws if specified value is greater than a minimum value)
  • Guard.GreaterThanOrEqualTo (throws if specified value is greater than or equal to a minimum value)
  • Guard.NotOutOfLength (throws if specified value is out of the range)
  • Guard.IsPositive (throws if specified value is not positive)
  • Guard.NotNegative (throws if specified value is negative)
  • Guard.NotZero (throws if specified value is zero)
  • Guard.PagingArgsValid (throws if specified value is out of the page range)


  • Guard.IsEqual (throws if )
  • Guard.Against (throws if )
  • Guard.Cast (throws if )
  • Guard.IsTrue (throws if )
  • Guard.IsFalse (throws if )
  • Guard.GetParamName (throws if )


  • Guard.IsFunction (throws if )
  • Guard.IsEnumType (throws if )
  • Guard.InheritsFrom (throws if )
  • Guard.Implements (throws if )
  • Guard.IsSubclassOf (throws if )
  • Guard.IsTypeOf (throws if )
  • Guard.HasDefaultConstructor (throws if )


public class CustomerController : Controller
    public IActionResult AddCustomer(Customer customer)
        // class (custom type) guard
        Guard.NotNull(customer, nameof(customer));

        // property guard
        Guard.NotNullOrEmpty(customer.Username, nameof(customer.Username));

        // explicit message
        Guard.NotNullOrEmpty(customer.FirstName, nameof(customer.FirstName), "Firstname is required");

        // int range guard
        Guard.GreaterThanOrEqualTo(10, 50, nameof(customer.Age));

        // bool guard
        Guard.IsFalse(customer.IsActive, nameof(customer.IsActive));

        return Ok();

    public IActionResult FindCustomer(string username)
        Guard.NotNullOrEmpty(username, nameof(username));

        return Ok();

    public IActionResult GetCustomerByAge(int age)
        // int range guard
        Guard.GreaterThanOrEqualTo(10, 50, nameof(age));

        return Ok();

    public IActionResult GetActiveCustomers(bool isActive)
        // bool guard
        Guard.IsFalse(isActive, nameof(isActive));

        return Ok();

    public IActionResult AddCustomer<T>(T customer) where T : class
        // generic type guard
        Guard.NotNull<T>(customer, nameof(customer));

        return Ok();

    public IActionResult AddCustomers(List<Customer> customers)
        // list guard
        Guard.NotNull(customers, nameof(customers));

        return Ok();
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 net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.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.
  • .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.

Version Downloads Last updated
2.0.0 15,210 6/24/2018
1.0.0 823 5/14/2018

1. new guard clauses support
     2. more customizable and extensive
     3. code re-factoring