-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/nuget/Microsoft.NET.Test.Sdk-17.8.0
- Loading branch information
Showing
9 changed files
with
229 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/GuardClauses/GuardAgainstExpressionExtensionsDeprecated.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ardalis.GuardClauses; | ||
|
||
public static partial class GuardClauseExtensions | ||
{ | ||
/// <summary> | ||
/// Throws an <see cref="ArgumentException" /> if <paramref name="func"/> evaluates to false for given <paramref name="input"/> | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="func"></param> | ||
/// <param name="guardClause"></param> | ||
/// <param name="input"></param> | ||
/// <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.")] | ||
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); | ||
} | ||
|
||
return input; | ||
} | ||
|
||
/// <summary> | ||
/// Throws an <see cref="ArgumentException" /> if <paramref name="func"/> evaluates to false for given <paramref name="input"/> | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="func"></param> | ||
/// <param name="guardClause"></param> | ||
/// <param name="input"></param> | ||
/// <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.")] | ||
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); | ||
} | ||
|
||
return input; | ||
} | ||
|
||
/// <summary> | ||
/// Throws an <see cref="ArgumentException" /> if <paramref name="func"/> evaluates to false for given <paramref name="input"/> | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="func"></param> | ||
/// <param name="guardClause"></param> | ||
/// <param name="input"></param> | ||
/// <param name="message"></param> | ||
/// <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.")] | ||
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); | ||
} | ||
|
||
return input; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.