Phema.Validation 3.0.2

C# strongly typed validation library for .NET

There is a newer version of this package available.
See the version list below for details.
This package is considered a SemVer 2.0.0 package as it has a package dependency on SemVer 2.0.0 package(s).
This package will only be available to download with SemVer 2.0.0 compatible NuGet clients, such as Visual Studio 2017 (version 15.3) and above or NuGet client 4.3.0 and above. Read more
Install-Package Phema.Validation -Version 3.0.2
dotnet add package Phema.Validation --version 3.0.2
<PackageReference Include="Phema.Validation" Version="3.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Phema.Validation --version 3.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Phema.Validation

Build Status
Nuget

C# strongly typed validation library for .NET

Installation

$> dotnet add package Phema.Validation

Usage

// Add
services.AddValidation(options => ...);

// Get or inject
var validationContext = serviceProvider.GetRequiredService<IValidationContext>();

// Use with a lot of validation rules (Check for Phema.Validation.Conditions namespace)
validationContext.When(person, p => p.Name)
  .IsNullOrWhitespace()
  .Is(name => ...Custom checks...)
  .AddError("Name must be set");

// Get validation details. Null if valid
var details = validationContext.When(person, p => p.Age)
  .IsNull()
  .AddError("Age must be set");

// Throw details when completely invalid state
validationContext.When(model, m => m.Address)
  .IsNull()
  .ThrowFatal("Address is not presented!!!"); // If invalid throw ValidationConditionException

// Validate collections
for(var index = 0; index < 10; index++)
{
  var forCollection = validationContext.CreateFor(model, m => m.Collection[index]);

  // It will produce `Collection[0].Property` key. 0 - concrete index
  forCollection.When(model.Collection[index], m => m.Property)
    .IsNull()
    .AddError($"Property is null. Index: {index}");

  // It will produce `Collection[0].Field` key. 0 - concrete index
  forCollection.When(model.Collection[index], m => m.Field)
    .IsNull()
    .AddError($"Field is null. Index: {index}");
}

// Check if context is valid
validationContext.IsValid();
validationContext.EnsureIsValid(); // If invalid throw ValidationContextException

// Check concrete validation details
validationContext.IsValid(person, p => p.Age);

// Create nested validationContext
ValidateChildren(validationContext.CreateFor(person, p => p.Children)) // It will be `Children.*ValidationKey*` path

// Combine paths
ValidateLocation(validationContext
  .CreateFor(person, p => p.Address)
  .CreateFor(person.Address, a => a.Location)) // It will be `Address.Location.*ValidationKey*` path

Phema.Validation

Build Status
Nuget

C# strongly typed validation library for .NET

Installation

$> dotnet add package Phema.Validation

Usage

// Add
services.AddValidation(options => ...);

// Get or inject
var validationContext = serviceProvider.GetRequiredService<IValidationContext>();

// Use with a lot of validation rules (Check for Phema.Validation.Conditions namespace)
validationContext.When(person, p => p.Name)
  .IsNullOrWhitespace()
  .Is(name => ...Custom checks...)
  .AddError("Name must be set");

// Get validation details. Null if valid
var details = validationContext.When(person, p => p.Age)
  .IsNull()
  .AddError("Age must be set");

// Throw details when completely invalid state
validationContext.When(model, m => m.Address)
  .IsNull()
  .ThrowFatal("Address is not presented!!!"); // If invalid throw ValidationConditionException

// Validate collections
for(var index = 0; index < 10; index++)
{
  var forCollection = validationContext.CreateFor(model, m => m.Collection[index]);

  // It will produce `Collection[0].Property` key. 0 - concrete index
  forCollection.When(model.Collection[index], m => m.Property)
    .IsNull()
    .AddError($"Property is null. Index: {index}");

  // It will produce `Collection[0].Field` key. 0 - concrete index
  forCollection.When(model.Collection[index], m => m.Field)
    .IsNull()
    .AddError($"Field is null. Index: {index}");
}

// Check if context is valid
validationContext.IsValid();
validationContext.EnsureIsValid(); // If invalid throw ValidationContextException

// Check concrete validation details
validationContext.IsValid(person, p => p.Age);

// Create nested validationContext
ValidateChildren(validationContext.CreateFor(person, p => p.Children)) // It will be `Children.*ValidationKey*` path

// Combine paths
ValidateLocation(validationContext
  .CreateFor(person, p => p.Address)
  .CreateFor(person.Address, a => a.Location)) // It will be `Address.Location.*ValidationKey*` path

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.1.10 21 10/12/2019
3.1.9 71 9/27/2019
3.1.8 66 9/25/2019
3.1.7 90 9/15/2019
3.1.6 47 9/8/2019
3.1.5 37 9/7/2019
3.1.4 36 9/7/2019
3.1.3 57 9/7/2019
3.1.2 36 8/25/2019
3.1.1 35 8/24/2019
3.1.0 36 8/23/2019
3.0.9 36 8/23/2019
3.0.8 37 8/22/2019
3.0.7 38 8/16/2019
3.0.6 39 7/30/2019
3.0.5 37 7/29/2019
3.0.4 37 7/29/2019
3.0.3 36 7/28/2019
3.0.2 36 7/21/2019
Show less