Skip to main content

SGuard

Lightweight, extensible guard clause library for .NET

Expressive and Robust

Two complementary APIs: ThrowIf.* for fail-fast validation and Is.* for boolean checks. Choose the style that fits your code.

Precise Diagnostics

Uses CallerArgumentExpression to automatically generate clear, helpful error messages that point to the exact argument that failed.

Comprehensive Guards

Null/empty checks, comparison guards, collection and span validation, email validation, custom exceptions, callbacks, and culture-aware string comparisons.

High Performance

Selector expressions are compiled once and cached in a thread-safe cache. Benchmarks available for all guard methods.

Modern .NET

Multi-targeting support for .NET 8, 9, and 10. Follows modern C# best practices and conventions.

Easy to Extend

Custom exception support, unified callback model, and built-in exceptions that derive fromArgumentException. Integrate seamlessly with your domain logic.