Пример #1
0
 /// <summary>
 /// Throws an <see cref="InvalidOperationException"/> if a <paramref name="value"/>
 /// <paramref name="condition"/> is False.
 /// </summary>
 /// <typeparam name="T">The Value type.</typeparam>
 /// <param name="value">The Value.</param>
 /// <param name="condition">The Condition which returns True to avoid <see cref="InvalidOperationException"/>.</param>
 /// <param name="message">The message for use with the thrown exception.</param>
 /// <returns>The <paramref name="value"/> after Operation <paramref name="condition"/> is Verified.</returns>
 public static T VerifyOperation <T>(this T value, FluentConditionCallback <T> condition, FluentMessageCallback message)
 {
     Verify.Operation(condition.Invoke(value), message.Invoke());
     return(value);
 }
Пример #2
0
 /// <summary>
 /// Conditionally throws an <see cref="InvalidOperationException"/> based on the
 /// <paramref name="condition"/>.
 /// </summary>
 /// <param name="_">A do not care place holder to root the extension method.</param>
 /// <param name="condition">Condition must return true to avoid failing the operation.</param>
 /// <param name="message">The message to use with the thrown exception.</param>
 /// <returns>The root place holder after Fail Operation is Verified.</returns>
 public static Exception VerifyFailOperation(this object _, FluentConditionCallback <object> condition, FluentMessageCallback message)
 => condition.Invoke(_) ? default : Verify.FailOperation(message.Invoke());
Пример #3
0
 /// <summary>
 /// Throws an <see cref="ObjectDisposedException"/> when <paramref name="condition"/>
 /// is False.
 /// </summary>
 /// <typeparam name="T">The Value type.</typeparam>
 /// <param name="value">The Value whose <see cref="IDisposable"/> is under consideration.</param>
 /// <param name="condition">the condition which returns True to avoid <see cref="ObjectDisposedException"/>.</param>
 /// <param name="message">The message to use for the thrown exception.</param>
 /// <returns>The <paramref name="value"/> after Not Disposed <paramref name="condition"/> is Verified.</returns>
 public static T VerifyValueNotDisposed <T>(this T value, FluentConditionCallback <T> condition, FluentMessageCallback message = null)
     where T : IDisposable
 {
     Verify.NotDisposed(condition.Invoke(value), value, message?.Invoke());
     return(value);
 }
 /// <summary>
 /// Validates some expression describing the acceptable <paramref name="condition"/>
 /// for an argument Evaluates to True.
 /// </summary>
 /// <typeparam name="T">The type of the argument.</typeparam>
 /// <param name="value">The Value of the argument.</param>
 /// <param name="condition">The expression that must Evaluate to True to avoid an <see cref="InvalidOperationException"/>.</param>
 /// <param name="message">The message to include with the exception.</param>
 /// <returns>The <paramref name="value"/> after Valid State <paramref name="condition"/> is Required.</returns>
 public static T RequiresValidState <T>(this T value, FluentConditionCallback <T> condition, FluentMessageCallback message)
 {
     Requires.ValidState(condition.Invoke(value), message.Invoke());
     return(value);
 }
 /// <summary>
 /// Throws an <see cref="ArgumentException"/> if a <paramref name="condition"/>
 /// does not evaluate to True.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="argument"></param>
 /// <param name="condition"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static T RequiresArgument <T>(this T argument, FluentConditionCallback <T> condition, string argumentName, FluentMessageCallback message)
 {
     Requires.Argument(condition.Invoke(argument), argumentName, message.Invoke());
     return(argument);
 }
 /// <summary>
 /// Validates some expression describing the acceptable <paramref name="condition"/>
 /// for an argument <paramref name="value"/> Evaluates to True.
 /// </summary>
 /// <typeparam name="T">The type of the argument.</typeparam>
 /// <param name="value">The Value of the argument.</param>
 /// <param name="condition">The Condition to Evaluate to True to avoid an <see cref="ArgumentException"/>.</param>
 /// <param name="argumentName">The name of the argument.</param>
 /// <param name="message">The message.</param>
 /// <returns>The <paramref name="value"/> after That <paramref name="value"/> is Required.</returns>
 public static T RequiresThat <T>(this T value, FluentConditionCallback <T> condition, string argumentName, FluentMessageCallback message)
 {
     Requires.That(condition.Invoke(value), argumentName, message.Invoke());
     return(value);
 }
 /// <summary>
 /// Throws an <see cref="ArgumentOutOfRangeException"/> if a <paramref name="condition"/>
 /// Does Not Evaluate to True.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="value"></param>
 /// <param name="condition"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 /// <returns>The <paramref name="value"/> after Range <paramref name="condition"/> is Required.</returns>
 public static T RequiresRange <T>(this T value, FluentConditionCallback <T> condition, string argumentName, FluentMessageCallback message = null)
 {
     Requires.Range(condition.Invoke(value), argumentName, message.UseCallbackOrDefault().Invoke());
     return(value);
 }