Phema.Validation 3.0.3

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.3
dotnet add package Phema.Validation --version 3.0.3
<PackageReference Include="Phema.Validation" Version="3.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Phema.Validation --version 3.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Phema.Validation

Build Status
Nuget

C# strongly typed expression-based validation library for .NET

Installation

$> dotnet add package Phema.Validation

Usage (example)

// Add `IValidationContext` as scoped service
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 exception when details severity greater than ValidationContext.ValidationSeverity
validationContext.When(person, p => p.Address)
  .IsNull()
  .AddFatal("Address is not presented!!!"); // If invalid throw ValidationConditionException

// Validate collections
validationContext.When(person, p => p.Children)
  .IsEmpty()
  .AddError("You have no children")

// 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
// It will be `Child.*ValidationKey*` path
ValidateChild(validationContext.CreateFor(parent, p => p.Child))

// Combine paths
// It will be `Address.Locations[0].*ValidationKey*` path
ValidateLocation(validationContext.CreateFor(person, p => p.Address.Locations[0]))

// It will be `Address.Locations[0].Latitude`
validationContext.When(person, p => p.Address.Locations[0].Latitude)
  .Is(latitude => ...)
  .AddError("Some custom check failed");
  
// Override validation key parts with `DataMemberAttribute`
[DataMember(Name = "age")]
public int Age { get; set; }

Phema.Validation

Build Status
Nuget

C# strongly typed expression-based validation library for .NET

Installation

$> dotnet add package Phema.Validation

Usage (example)

// Add `IValidationContext` as scoped service
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 exception when details severity greater than ValidationContext.ValidationSeverity
validationContext.When(person, p => p.Address)
  .IsNull()
  .AddFatal("Address is not presented!!!"); // If invalid throw ValidationConditionException

// Validate collections
validationContext.When(person, p => p.Children)
  .IsEmpty()
  .AddError("You have no children")

// 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
// It will be `Child.*ValidationKey*` path
ValidateChild(validationContext.CreateFor(parent, p => p.Child))

// Combine paths
// It will be `Address.Locations[0].*ValidationKey*` path
ValidateLocation(validationContext.CreateFor(person, p => p.Address.Locations[0]))

// It will be `Address.Locations[0].Latitude`
validationContext.When(person, p => p.Address.Locations[0].Latitude)
  .Is(latitude => ...)
  .AddError("Some custom check failed");
  
// Override validation key parts with `DataMemberAttribute`
[DataMember(Name = "age")]
public int Age { get; set; }

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.1.10 16 10/12/2019
3.1.9 68 9/27/2019
3.1.8 63 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