LawBook 1.3.7
dotnet add package LawBook --version 1.3.7
NuGet\Install-Package LawBook -Version 1.3.7
<PackageReference Include="LawBook" Version="1.3.7" />
paket add LawBook --version 1.3.7
#r "nuget: LawBook, 1.3.7"
// Install LawBook as a Cake Addin #addin nuget:?package=LawBook&version=1.3.7 // Install LawBook as a Cake Tool #tool nuget:?package=LawBook&version=1.3.7
LawBook
LawBook provide some classes that helps you to do validations on your own classes. You can validate a lot of things, if values match or not, is on a specified interval, is contained on a list of values, match to a regex expression and a lot of other things. This is based on the <b>Assertion Concern</b> pattern proposed by Vernon Vaughn on his book called Implementing Domain-Driven Design.
This project was made because in a lot of projects I had to reproduce this validations structures, so I came with the idea to create a package with this solution and share with people who might find this helpfull.
The name of the solution, classes and methods came with an analogy to the law principles, where is specified your rights, rules and obligations to live in a society. So, in a software conception, the objects must follow too the rights, rules and obligations to make a software as expected.
How to use
You can run the validations in two ways:
- Calling in code explicitly each of the validations;
- Encapsule all the validations in a method and call by an Executor.
The first way is calling it explicitly, just call the method of the validation needed whever you want:
Law.MustBeTrue(1 > 2, "1 is not higher than 2!");
So, when you call this expression is going to throw an GuiltyException, because the validation failed.
And the other is encapsuling the validations in a method and call than with an executor, this way the validations are going to be centralized and you can call at the moment you want and multiple times.
public class Car : ILawable
{
public string FuelType { get; set; }
public int Wheels { get; set; }
public int Doors { get; set; }
public Car(string fuel, int wheels, int doors)
{
FuelType = fuel;
Wheels = wheels;
Doors = doors;
}
public void Validate()
{
Law.MustBeContained(FuelType, new string[] { "Gasoline", "Biodiesel" }, "Invalid Fuel Type");
Law.MustBeEquals(Wheels, 4, "Invalid Number of Wheels");
Law.MustBeContained(Doors, new int[] { 2, 4}, "Invalid Number of Doors");
}
}
For example, this class Car, was created the method Validate, inherited by the interface ILawable flaging that this class is validatable. And on the method you can see all the validations that an object of the type Car must follow.
And after to trigger the validations you can do this by two ways:
The simple one, like all methods are called:
myCar.Validate();
And using an executor:
Judge.Sentence(myCar, false);
But, why using an executor to run the method? You can do this just calling the Validate()
.
This is because, with the Executor we can pass configurations and manage how the validations are going to be executed.
This project is young, and the executor currently only have a flag to silence or not the thrown of the exception. Have a lot more planned to grow and make this more suitable and strong solution.
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 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.2 is compatible. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net451 was computed. net452 was computed. net46 was computed. 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 | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wpa81 was computed. |
Windows Store | netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.2
- NETStandard.Library (>= 1.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.