Skip to content

Commit

Permalink
Update Obsolete message to note reversal of logic. (#357)
Browse files Browse the repository at this point in the history
Fixes #356
  • Loading branch information
ardalis authored Sep 30, 2024
1 parent dc2b6e8 commit fbe4c3d
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/GuardClauses/GuardAgainstExpressionExtensionsDeprecated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ public static partial class GuardClauseExtensions
/// <param name="message"></param>
/// <returns><paramref name="input"/> if the <paramref name="func"/> evaluates to true </returns>
/// <exception cref="ArgumentException"></exception>
[Obsolete("Deprecated: Switch to Expression for validation.")]
[Obsolete("Deprecated: Switch to Expression for validation (and reverse logic).")]
public static T AgainstExpression<T>(this IGuardClause guardClause,
Func<T, bool> func,
T input,
string message) where T : struct
{
if (!func(input))
{
throw new ArgumentException(message);
}
if (!func(input)) throw new ArgumentException(message);

return input;
}
Expand All @@ -39,16 +36,13 @@ public static T AgainstExpression<T>(this IGuardClause guardClause,
/// <param name="message"></param>
/// <returns><paramref name="input"/> if the <paramref name="func"/> evaluates to true </returns>
/// <exception cref="ArgumentException"></exception>
[Obsolete("Deprecated: Switch to ExpressionAsync for asynchronous validation.")]
[Obsolete("Deprecated: Switch to ExpressionAsync for asynchronous validation (and reverse logic).")]
public static async Task<T> AgainstExpressionAsync<T>(this IGuardClause guardClause,
Func<T, Task<bool>> func,
T input,
string message) where T : struct
{
if (!await func(input))
{
throw new ArgumentException(message);
}
if (!await func(input)) throw new ArgumentException(message);

return input;
}
Expand All @@ -64,14 +58,11 @@ public static async Task<T> AgainstExpressionAsync<T>(this IGuardClause guardCla
/// <param name="paramName">The name of the parameter that is invalid</param>
/// <returns><paramref name="input"/> if the <paramref name="func"/> evaluates to true </returns>
/// <exception cref="ArgumentException"></exception>
[Obsolete("Deprecated: Switch to Expression for validation.")]
[Obsolete("Deprecated: Switch to Expression for validation (and reverse logic).")]
public static T AgainstExpression<T>(this IGuardClause guardClause, Func<T, bool> func,
T input, string message, string paramName) where T : struct
{
if (!func(input))
{
throw new ArgumentException(message, paramName);
}
if (!func(input)) throw new ArgumentException(message, paramName);

return input;
}
Expand Down

0 comments on commit fbe4c3d

Please sign in to comment.