LiteX.Guard
1.0.0
See the version list below for details.
dotnet add package LiteX.Guard --version 1.0.0
NuGet\Install-Package LiteX.Guard -Version 1.0.0
<PackageReference Include="LiteX.Guard" Version="1.0.0" />
paket add LiteX.Guard --version 1.0.0
#r "nuget: LiteX.Guard, 1.0.0"
// Install LiteX.Guard as a Cake Addin #addin nuget:?package=LiteX.Guard&version=1.0.0 // Install LiteX.Guard as a Cake Tool #tool nuget:?package=LiteX.Guard&version=1.0.0
LiteXGuard
LiteX.Guard is a simple guard clause argument validation library, that helps you with validation of your arguments.
A simple package with guard clause helper methods. This library provides guard clauses that could be used to guard against not expected values. It provides conditions for objects, strings, numerics, datatime and enumerables. It is possible to configure which exception should be thrown.
Argument validation made simple and unified. It ensures arguments conforms to simple validation rules and provides an uniformed exception throwing strategy if arguments are invalid.
It's developed for .NET Standard 2.0 and available via NuGet.
Install Nuget package
Run the nuget command for installing the client as,
Install-Package LiteX.Guard
Supported Guard Clauses
Null/Empty
- Guard.NotNull (throws if input is null)
- Guard.NotNullOrEmpty (throws if string input is null or empty)
Range
- 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)
Misc
- Guard.IsEqual (throws if )
- Guard.Against (throws if )
- Guard.Cast (throws if )
- Guard.IsTrue (throws if )
- Guard.IsFalse (throws if )
- Guard.GetParamName (throws if )
Type
- 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 )
Usage
public class CustomerController : Controller
{
[HttpPost]
[Route("add-customer")]
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();
}
[HttpGet]
[Route("find-customer")]
public IActionResult FindCustomer(string username)
{
Guard.NotNullOrEmpty(username, nameof(username));
return Ok();
}
[HttpGet]
[Route("get-customer-by-age")]
public IActionResult GetCustomerByAge(int age)
{
// int range guard
Guard.GreaterThanOrEqualTo(10, 50, nameof(age));
return Ok();
}
[HttpGet]
[Route("get-active-customers")]
public IActionResult GetActiveCustomers(bool isActive)
{
// bool guard
Guard.IsFalse(isActive, nameof(isActive));
return Ok();
}
[HttpPost]
[Route("add-customer-T")]
public IActionResult AddCustomer<T>(T customer) where T : class
{
// generic type guard
Guard.NotNull<T>(customer, nameof(customer));
return Ok();
}
[HttpPost]
[Route("add-customers")]
public IActionResult AddCustomers(List<Customer> customers)
{
// list guard
Guard.NotNull(customers, nameof(customers));
return Ok();
}
}
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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. 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 | 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. |
-
.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.
A simple package with guard clause helper extension methods.