RValidator 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package RValidator --version 1.0.0
                    
NuGet\Install-Package RValidator -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="RValidator" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RValidator" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="RValidator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RValidator --version 1.0.0
                    
#r "nuget: RValidator, 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.
#:package RValidator@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RValidator&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=RValidator&version=1.0.0
                    
Install as a Cake Tool

RValidator

Fluent validation library for .NET inspired by FluentValidation. Define strongly-typed validation rules using a fluent, readable, and maintainable API.

Features

  • Fluent API with RuleFor and RuleForEach
  • Built-in validators (NotEmpty, EmailAddress, Length, GreaterThan, etc.)
  • Conditional validation with When and Unless
  • Cascade mode (Continue / Stop)
  • Child validators with SetValidator
  • Async validation with MustAsync
  • Custom messages and error codes
  • Partial property validation
  • Dependency injection integration
  • Full XML documentation

Requirements

  • .NET 8.0 or later

Installation

Add a project reference:

dotnet add reference src/RValidator/RValidator.csproj

Or, after NuGet publication:

dotnet add package RValidator

Quick start

1. Define the model

public class Customer
{
    public string? Name { get; set; }
    public string? Email { get; set; }
    public int Age { get; set; }
}

2. Create the validator

using RValidator;

public class CustomerValidator : AbstractValidator<Customer>
{
    public CustomerValidator()
    {
        RuleFor(x => x.Name)
            .NotEmpty()
            .MinimumLength(2)
            .MaximumLength(100);

        RuleFor(x => x.Email)
            .NotEmpty()
            .EmailAddress()
            .WithMessage("Please provide a valid email address.");

        RuleFor(x => x.Age)
            .InclusiveBetween(18, 120);
    }
}

3. Run validation

var customer = new Customer { Name = "John", Email = "john@example.com", Age = 30 };
var validator = new CustomerValidator();
var result = validator.Validate(customer);

if (!result.IsValid)
{
    foreach (var error in result.Errors)
    {
        Console.WriteLine($"{error.PropertyName}: {error.ErrorMessage}");
    }
}

Validation with exceptions

validator.ValidateAndThrow(customer);

// or async
await validator.ValidateAndThrowAsync(customer);

Throws ValidationException containing the full ValidationResult.

Async validation

RuleFor(x => x.Email)
    .MustAsync(async (email, cancellation) =>
    {
        await Task.Delay(100, cancellation);
        return !await EmailExistsInDatabase(email);
    })
    .WithMessage("Email is already registered.");

Conditional validation

RuleFor(x => x.Discount)
    .NotEqual(0m)
    .When(x => x.HasDiscount);

RuleFor(x => x.MiddleName)
    .NotEmpty()
    .Unless(x => x.UseSingleName);

Child validators

public class CustomerValidator : AbstractValidator<Customer>
{
    public CustomerValidator()
    {
        RuleFor(x => x.Address)
            .SetValidator(new AddressValidator());
    }
}

Collection validation

RuleForEach(x => x.Orders)
    .SetValidator(new OrderLineValidator());

RuleFor(x => x.Orders)
    .NotEmpty();

Cascade mode

RuleFor(x => x.FirstName)
    .Cascade(CascadeMode.Stop)
    .NotEmpty()
    .MinimumLength(2);

With Stop, execution stops after the first failure in the chain.

Dependency injection

using RValidator.DependencyInjection;

builder.Services.AddValidatorsFromAssemblyContaining<CustomerValidator>();

// Resolution
var validator = serviceProvider.GetRequiredService<IValidator<Customer>>();

Built-in validators

Method Description
NotNull() Value must not be null
Null() Value must be null
NotEmpty() String/collection must not be empty
Empty() String must be empty
Equal(value) Value must be equal
NotEqual(value) Value must not be equal
Length(min, max) String length within range
MinimumLength(n) Minimum length
MaximumLength(n) Maximum length
GreaterThan(value) Greater than
GreaterThanOrEqualTo(value) Greater than or equal
LessThan(value) Less than
LessThanOrEqualTo(value) Less than or equal
InclusiveBetween(from, to) Between inclusive bounds
ExclusiveBetween(from, to) Between exclusive bounds
EmailAddress() Valid email format
Matches(pattern) Matches regex
Must(predicate) Custom validation
MustAsync(predicate) Async custom validation

Project structure

rvalidator/
├── src/RValidator/
│   ├── Abstractions/          # Public contracts (IValidator, IRuleBuilder)
│   ├── Enums/                 # CascadeMode, Severity
│   ├── Extensions/            # Built-in validator extensions
│   ├── DependencyInjection/   # DI registration helpers
│   └── Internal/              # Internal implementation
├── tests/RValidator.Tests/  # Unit tests (xUnit)
├── docs/                      # Detailed documentation
└── RValidator.slnx          # Solution

Run tests

dotnet test

Additional documentation

License

See LICENSE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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