Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETSTANDARD2_1
#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER

namespace System.Runtime.CompilerServices;

Expand Down
12 changes: 4 additions & 8 deletions src/GuardClauses/GuardAgainstExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ public static T Expression<T>(this IGuardClause guardClause,
Func<T, bool> func,
T input,
string message,
#if NET7_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
[CallerArgumentExpression("input")]
#endif
string? parameterName = null) where T : struct
[CallerArgumentExpression("input")] string? parameterName = null)
where T : struct
{
if (func(input))
{
Expand All @@ -53,10 +51,8 @@ public static async Task<T> ExpressionAsync<T>(this IGuardClause guardClause,
Func<T, Task<bool>> func,
T input,
string message,
#if NET7_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
[CallerArgumentExpression("input")]
#endif
string? parameterName = null) where T : struct
[CallerArgumentExpression("input")] string? parameterName = null)
where T : struct
{
if (await func(input))
{
Expand Down
98 changes: 0 additions & 98 deletions src/GuardClauses/GuardAgainstNegativeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@ public static partial class GuardClauseExtensions
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative.</returns>
/// <exception cref="ArgumentException"></exception>
#if NETFRAMEWORK || NETSTANDARD2_0
public static int Negative(this IGuardClause guardClause,
int input,
string parameterName,
string? message = null)
#else
public static int Negative(this IGuardClause guardClause,
int input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return Negative<int>(guardClause, input, parameterName, message);
}
Expand All @@ -38,17 +31,10 @@ public static int Negative(this IGuardClause guardClause,
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative.</returns>
/// <exception cref="ArgumentException"></exception>
#if NETFRAMEWORK || NETSTANDARD2_0
public static long Negative(this IGuardClause guardClause,
long input,
string parameterName,
string? message = null)
#else
public static long Negative(this IGuardClause guardClause,
long input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return Negative<long>(guardClause, input, parameterName, message);
}
Expand All @@ -62,17 +48,10 @@ public static long Negative(this IGuardClause guardClause,
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative.</returns>
/// <exception cref="ArgumentException"></exception>
#if NETFRAMEWORK || NETSTANDARD2_0
public static decimal Negative(this IGuardClause guardClause,
decimal input,
string parameterName,
string? message = null)
#else
public static decimal Negative(this IGuardClause guardClause,
decimal input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return Negative<decimal>(guardClause, input, parameterName, message);
}
Expand All @@ -86,17 +65,10 @@ public static decimal Negative(this IGuardClause guardClause,
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative.</returns>
/// <exception cref="ArgumentException"></exception>
#if NETFRAMEWORK || NETSTANDARD2_0
public static float Negative(IGuardClause guardClause,
float input,
string parameterName,
string? message = null)
#else
public static float Negative(this IGuardClause guardClause,
float input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return Negative<float>(guardClause, input, parameterName, message);
}
Expand All @@ -110,17 +82,10 @@ public static float Negative(this IGuardClause guardClause,
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative.</returns>
/// <exception cref="ArgumentException"></exception>
#if NETFRAMEWORK || NETSTANDARD2_0
public static double Negative(this IGuardClause guardClause,
double input,
string parameterName,
string? message = null)
#else
public static double Negative(this IGuardClause guardClause,
double input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return Negative<double>(guardClause, input, parameterName, message);
}
Expand All @@ -134,17 +99,10 @@ public static double Negative(this IGuardClause guardClause,
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative.</returns>
/// <exception cref="ArgumentException"></exception>
#if NETFRAMEWORK || NETSTANDARD2_0
public static TimeSpan Negative(this IGuardClause guardClause,
TimeSpan input,
string parameterName,
string? message = null)
#else
public static TimeSpan Negative(this IGuardClause guardClause,
TimeSpan input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return Negative<TimeSpan>(guardClause, input, parameterName, message);
}
Expand All @@ -158,17 +116,10 @@ public static TimeSpan Negative(this IGuardClause guardClause,
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative.</returns>
/// <exception cref="ArgumentException"></exception>
#if NETFRAMEWORK || NETSTANDARD2_0
private static T Negative<T>(this IGuardClause guardClause,
T input,
string parameterName,
string? message = null) where T : struct, IComparable
#else
private static T Negative<T>(this IGuardClause guardClause,
T input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null) where T : struct, IComparable
#endif
{
if (input.CompareTo(default(T)) < 0)
{
Expand All @@ -186,17 +137,10 @@ private static T Negative<T>(this IGuardClause guardClause,
/// <param name="parameterName"></param>
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
#if NETFRAMEWORK || NETSTANDARD2_0
public static int NegativeOrZero(this IGuardClause guardClause,
int input,
string parameterName,
string? message = null)
#else
public static int NegativeOrZero(this IGuardClause guardClause,
int input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return NegativeOrZero<int>(guardClause, input, parameterName, message);
}
Expand All @@ -209,17 +153,10 @@ public static int NegativeOrZero(this IGuardClause guardClause,
/// <param name="parameterName"></param>
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
#if NETFRAMEWORK || NETSTANDARD2_0
public static long NegativeOrZero(this IGuardClause guardClause,
long input,
string parameterName,
string? message = null)
#else
public static long NegativeOrZero(this IGuardClause guardClause,
long input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return NegativeOrZero<long>(guardClause, input, parameterName, message);
}
Expand All @@ -232,17 +169,10 @@ public static long NegativeOrZero(this IGuardClause guardClause,
/// <param name="parameterName"></param>
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
#if NETFRAMEWORK || NETSTANDARD2_0
public static decimal NegativeOrZero(this IGuardClause guardClause,
decimal input,
string parameterName,
string? message = null)
#else
public static decimal NegativeOrZero(this IGuardClause guardClause,
decimal input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return NegativeOrZero<decimal>(guardClause, input, parameterName, message);
}
Expand All @@ -255,17 +185,10 @@ public static decimal NegativeOrZero(this IGuardClause guardClause,
/// <param name="parameterName"></param>
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
#if NETFRAMEWORK || NETSTANDARD2_0
public static float NegativeOrZero(this IGuardClause guardClause,
float input,
string parameterName,
string? message = null)
#else
public static float NegativeOrZero(this IGuardClause guardClause,
float input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return NegativeOrZero<float>(guardClause, input, parameterName, message);
}
Expand All @@ -278,17 +201,10 @@ public static float NegativeOrZero(this IGuardClause guardClause,
/// <param name="parameterName"></param>
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
#if NETFRAMEWORK || NETSTANDARD2_0
public static double NegativeOrZero(this IGuardClause guardClause,
double input,
string parameterName,
string? message = null)
#else
public static double NegativeOrZero(this IGuardClause guardClause,
double input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return NegativeOrZero<double>(guardClause, input, parameterName, message);
}
Expand All @@ -301,17 +217,10 @@ public static double NegativeOrZero(this IGuardClause guardClause,
/// <param name="parameterName"></param>
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
#if NETFRAMEWORK || NETSTANDARD2_0
public static TimeSpan NegativeOrZero(this IGuardClause guardClause,
TimeSpan input,
string parameterName,
string? message = null)
#else
public static TimeSpan NegativeOrZero(this IGuardClause guardClause,
TimeSpan input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null)
#endif
{
return NegativeOrZero<TimeSpan>(guardClause, input, parameterName, message);
}
Expand All @@ -325,17 +234,10 @@ public static TimeSpan NegativeOrZero(this IGuardClause guardClause,
/// <param name="parameterName"></param>
/// <param name="message">Optional. Custom error message</param>
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
#if NETFRAMEWORK || NETSTANDARD2_0
private static T NegativeOrZero<T>(this IGuardClause guardClause,
T input,
string parameterName,
string? message = null) where T : struct, IComparable
#else
private static T NegativeOrZero<T>(this IGuardClause guardClause,
T input,
[CallerArgumentExpression("input")] string? parameterName = null,
string? message = null) where T : struct, IComparable
#endif
{
if (input.CompareTo(default(T)) <= 0)
{
Expand Down
14 changes: 0 additions & 14 deletions src/GuardClauses/GuardAgainstNotFoundExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@ public static partial class GuardClauseExtensions
/// <param name="parameterName"></param>
/// <returns><paramref name="input" /> if the value is not null.</returns>
/// <exception cref="NotFoundException"></exception>
#if NETFRAMEWORK || NETSTANDARD2_0
public static T NotFound<T>(this IGuardClause guardClause,
[NotNull][ValidatedNotNull] string key,
[NotNull][ValidatedNotNull] T? input,
string parameterName)
#else
public static T NotFound<T>(this IGuardClause guardClause,
[NotNull][ValidatedNotNull] string key,
[NotNull][ValidatedNotNull] T? input,
[CallerArgumentExpression("input")] string? parameterName = null)
#endif
{
guardClause.NullOrEmpty(key, nameof(key));

Expand All @@ -48,17 +41,10 @@ public static T NotFound<T>(this IGuardClause guardClause,
/// <param name="parameterName"></param>
/// <returns><paramref name="input" /> if the value is not null.</returns>
/// <exception cref="NotFoundException"></exception>
#if NETFRAMEWORK || NETSTANDARD2_0
public static T NotFound<TKey, T>(this IGuardClause guardClause,
[NotNull][ValidatedNotNull] TKey key,
[NotNull][ValidatedNotNull] T? input,
string parameterName) where TKey : struct
#else
public static T NotFound<TKey, T>(this IGuardClause guardClause,
[NotNull][ValidatedNotNull] TKey key,
[NotNull][ValidatedNotNull]T? input,
[CallerArgumentExpression("input")] string? parameterName = null) where TKey : struct
#endif
{
guardClause.Null(key, nameof(key));

Expand Down
Loading