FailOr.Validations 1.1.0

dotnet add package FailOr.Validations --version 1.1.0
                    
NuGet\Install-Package FailOr.Validations -Version 1.1.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="FailOr.Validations" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FailOr.Validations" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="FailOr.Validations" />
                    
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 FailOr.Validations --version 1.1.0
                    
#r "nuget: FailOr.Validations, 1.1.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 FailOr.Validations@1.1.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=FailOr.Validations&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=FailOr.Validations&version=1.1.0
                    
Install as a Cake Tool

FailOr.Validations

NuGet Version NuGet Downloads CI Targets License

FailOr.Validations is the typed companion package for property-based validation on plain T values. It builds on top of FailOr and adds selector-driven validation and validation-plus-transform helpers.

Install

dotnet add package FailOr.Validations

FailOr.Validations depends on FailOr, so the core package is restored automatically.

Behavior

  • Validate(...) and ValidateAsync(...) run one or more property-based validators and return the original input instance on success.
  • ValidateThenTransform(...) and ValidateThenTransformAsync(...) run one or more property-based mappers and invoke the final transform only when every mapper succeeds.
  • Only Failures.Validation instances are rewritten to the selected leaf property name such as Name or City.
  • Failures.General and Failures.Exceptional are preserved unchanged.
  • Async validators and async mappers run sequentially and preserve declaration order.

Quick Start

Validate and keep the original value:

using FailOr;
using FailOr.Validation;

var person = new Person
{
    Name = "Ada",
    Nickname = "Ace",
    Address = new Address { City = "Boston" }
};

var result = person.Validate(
    (x => x.Name, name => string.IsNullOrWhiteSpace(name)
        ? FailOr.Fail<int>(Failure.Validation("Ignored", "Name is required."))
        : FailOr.Success(1)),
    (x => x.Address.City, city => string.IsNullOrWhiteSpace(city)
        ? FailOr.Fail<int>(Failure.Validation("Ignored", "City is required."))
        : FailOr.Success(1)));

Map selected properties and transform the mapped values:

using FailOr;
using FailOr.Validation;

var result = person.ValidateThenTransform(
    (x => x.Name, name => string.IsNullOrWhiteSpace(name)
        ? FailOr.Fail<string>(Failure.Validation("Ignored", "Name is required."))
        : FailOr.Success(name.ToUpperInvariant())),
    (x => x.Address.City, city => string.IsNullOrWhiteSpace(city)
        ? FailOr.Fail<string>(Failure.Validation("Ignored", "City is required."))
        : FailOr.Success(city.ToUpperInvariant())),
    (name, city) => $"{name}|{city}");

Run async validators and async transforms:

using FailOr;
using FailOr.Validation;

var result = await person.ValidateThenTransformAsync(
    (x => x.Name, async name =>
    {
        await Task.Delay(1);
        return string.IsNullOrWhiteSpace(name)
            ? FailOr.Fail<string>(Failure.Validation("Ignored", "Name is required."))
            : FailOr.Success(name.ToUpperInvariant());
    }),
    async name =>
    {
        await Task.Delay(1);
        return $"Hello {name}";
    });

Documentation

License

Licensed under the MIT 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 is compatible.  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
1.1.0 100 3/15/2026