Skip to content

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 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)
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)
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)
NotNull(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)
True(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)
True(Func 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)
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)
True(Func 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)

Sources

  • Common/SAIF.Common/Classes/Enforce.cs