A fluent validation and guard clause library for .NET using pipe operators and C# extensions.
- 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
- .NET 10.0 or later
dotnet add package PipeExceptionusing 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");// Chain multiple conditions
int validatedValue = value
| (x => x > 0)
| (x => x < 100)
| (x => x % 2 == 0);// 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// 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();# Build
./build.sh compile # Linux/macOS
./build.cmd compile # Windows
# Test
./build.sh test
# Pack
./build.sh packThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
