Skip to content

Repository files navigation

PipeException banner

PipeException

Table of Contents

PipeException Logo

NuGet CI License: MIT

A fluent validation and guard clause library for .NET using pipe operators and C# extensions.

Features

  • Pipe Operator Validation: Use the | operator for inline validation
  • Fluent Chaining: Chain multiple validations together seamlessly
  • Custom Exception Types: Choose which exception to throw after validation
  • Built-in Validators: Common validators for strings, collections, nullables, and numeric types
  • Modern C# Syntax: Leverages C# extension methods for clean, readable code

Requirements

  • .NET 10.0 or later

Installation

dotnet add package PipeException

Quick Start

Basic Validation

using PipeException;

// Throws ArgumentException if condition is false
int positiveNumber = value | (x => x > 0);

// With custom error message
int rangedValue = value | (x => x is > 0 and < 100, "Value must be between 0 and 100");

Chained Validations

// Chain multiple conditions
int validatedValue = value
    | (x => x > 0)
    | (x => x < 100)
    | (x => x % 2 == 0);

Choose Exception Type

// Use ValidationResult for deferred exception selection
var result = value | (x => x >= 0);

// Throw specific exception types
result.OrThrowNull("paramName");           // ArgumentNullException
result.OrThrowInvalidOperation();          // InvalidOperationException
result.OrThrow<CustomException>();         // Custom exception
result.OrThrow(() => new MyException());   // Exception factory

Built-in Validators

// String validation
string name = input.EnsureNotNullOrEmpty();
string trimmed = input.EnsureNotNullOrWhiteSpace();
string sized = input.EnsureMinLength(3).EnsureMaxLength(50);

// Numeric validation
int positive = number | Validate.Positive;
int nonNegative = number | Validate.NonNegative;
int ranged = number | Validate.InRange(1, 100);

// Collection validation
var items = list.EnsureNotEmpty();
var sized = list.EnsureMinCount(1).EnsureMaxCount(10);

// Nullable validation
var notNull = nullableValue.EnsureNotNull();

Building from Source

# Build
./build.sh compile    # Linux/macOS
./build.cmd compile   # Windows

# Test
./build.sh test

# Pack
./build.sh pack

Tech Stack

  • .NET 10
  • xunit.v3
  • xunit.runner.visualstudio
  • Nuke.Common

Roadmap

Planned work and known limitations are tracked in the open issues. Contributions toward them are welcome.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


Built by Atypical Consulting. We also make NuGetKeep, a self-hosted NuGet server with supply-chain quarantine.

About

A fluent validation and guard clause library for .NET using pipe operators and C# extensions.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages