---
title: Enforce
summary: API reference for Enforce.
status: draft
owner: saif-docgen
last_reviewed: 2026-09-15
library: SAIF.Framework.Common
reference_type: package
---

# Enforce

Static fail-fast guard class used to validate method arguments and internal state before use; the guard layer that IEnumerableExtensions, DictionaryExtensions, and other members throughout the library call at the top of their bodies.

## Purpose
- Static fail-fast guard class used to validate method arguments and internal state before use; the guard layer that IEnumerableExtensions, DictionaryExtensions, and other members throughout the library call at the top of their bodies.

## Context
- Namespace: `SAIF`
- Assembly/package: `SAIF.Framework.Common`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| ArgumentNotNull<T>(T value, string parameterName) | `public static T ArgumentNotNull<T>(T value, string parameterName)` | Throws `ArgumentNullException(parameterName)` when `value` is null; otherwise returns `value` unchanged so the call can be chained. ([BR-039](../../business-rules.md#br-039-a-guarded-argument-must-not-be-null)) |
| ArgumentNotNullOrEmpty(string value, string parameterName) | `public static string ArgumentNotNullOrEmpty(string value, string parameterName)` | Runs the null guard first, then throws `ArgumentException` if the string is empty. ([BR-040](../../business-rules.md#br-040-a-guarded-string-argument-must-not-be-empty)) |
| ArgumentNotNullOrWhiteSpace(string value, string parameterName) | `public static string ArgumentNotNullOrWhiteSpace(string value, string parameterName)` | Runs the null guard first, then throws `ArgumentException` if the trimmed string has zero length. ([BR-041](../../business-rules.md#br-041-a-guarded-string-argument-must-not-be-all-white-space)) |
| NotNull<T>(T value) | `public static T NotNull<T>(T value)` | Throws `InvalidOperationException` when a piece of internal state (rather than an incoming argument) is null. ([BR-042](<../../business-rules.md#br-042-a-guarded-state-value-(as-opposed-to-an-argument)-must-not-be-null>)) |
| True<T>(bool condition) | `public static void True<T>(bool condition) where T : Exception, new()` | Throws a new parameterless instance of `T` when `condition` evaluates to false. ([BR-043](../../business-rules.md#br-043-a-caller-supplied-boolean-or-func%3Cbool%3E-condition-must-evaluate-true%2C-or-the-caller-specified-exception-type%2Finstance-is-thrown)) |
| True<T>(Func<bool> condition) | `public static void True<T>(Func<bool> condition) where T : Exception, new()` | Evaluates `condition` lazily and throws a new `T` only if it is false, avoiding eager evaluation of expensive checks. ([BR-043](../../business-rules.md#br-043-a-caller-supplied-boolean-or-func%3Cbool%3E-condition-must-evaluate-true%2C-or-the-caller-specified-exception-type%2Finstance-is-thrown)) |
| True(bool condition, Exception exception) | `public static void True(bool condition, Exception exception)` | Throws the caller-supplied `exception` instance (preserving its message/state) when `condition` is false. ([BR-043](../../business-rules.md#br-043-a-caller-supplied-boolean-or-func%3Cbool%3E-condition-must-evaluate-true%2C-or-the-caller-specified-exception-type%2Finstance-is-thrown)) |
| True(Func<bool> condition, Exception exception) | `public static void True(Func<bool> condition, Exception exception)` | Evaluates `condition` lazily and throws the supplied exception instance only if it is false. ([BR-043](../../business-rules.md#br-043-a-caller-supplied-boolean-or-func%3Cbool%3E-condition-must-evaluate-true%2C-or-the-caller-specified-exception-type%2Finstance-is-thrown)) |


## Sources
- `Common/SAIF.Common/Classes/Enforce.cs`
