SimplySoft.ThrowValidator 1.0.0

dotnet add package SimplySoft.ThrowValidator --version 1.0.0
NuGet\Install-Package SimplySoft.ThrowValidator -Version 1.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="SimplySoft.ThrowValidator" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimplySoft.ThrowValidator --version 1.0.0
#r "nuget: SimplySoft.ThrowValidator, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SimplySoft.ThrowValidator as a Cake Addin
#addin nuget:?package=SimplySoft.ThrowValidator&version=1.0.0

// Install SimplySoft.ThrowValidator as a Cake Tool
#tool nuget:?package=SimplySoft.ThrowValidator&version=1.0.0

Throw

Throw is a unified conditional validator designed for .NET built-in structures and types. Throw also simplifies multi-level guard conditions such as if-else and switch statements into single-line validator. Internally, Throw extends the behaviors of built-in types when its namespace is referred within current coding context.

Prerequisites

Throw requires .NET 5.0 (v5.#.#) or .NET 6.0 (v6.#.#).

Quick Demo

Throw can easily transform this 👇

int? age = 47;

if (age is null)
  throw new Exception();

if (age is 0)
  throw new Exception("Are you kidding?");
  
if (age < 0)
  throw new Exception("This is unreal!");
  
if (age >= 13 && age <= 19)
  throw new Exception("Teenagers not allowed!");

into a single minified expression like... 👇

age.Throw()
  .WhenNull()
  .WhenZero("Are you kidding?")
  .WhenNegative("This is unreal!")
  .WhenInRange(13, 19, Boundary.Inclusive, "Teenagers not allowed!");

Imgur

In other words, Throw can translate imperative flow of validations into a declarative statement

Note   There are more validations which can be done by Throw with other types as well...

Throw can easily chain multiple validations into a single in-line statement
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.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
1.0.0 198 8/21/2022