From 901616c608760843c52ed1d6fa0ee9d0dc336859 Mon Sep 17 00:00:00 2001 From: Ergamon <48294299+Ergamon@users.noreply.github.com> Date: Sat, 10 Feb 2024 21:03:06 +0100 Subject: [PATCH 1/3] Removed different method signatures for NETFRAMEWORK and NETSTANDARD2_0 (#338) Co-authored-by: Gerald Mahlmeister --- .../CallerArgumentExpressionAttribute.cs | 2 +- .../GuardAgainstExpressionExtensions.cs | 12 +-- .../GuardAgainstNegativeExtensions.cs | 98 ------------------- .../GuardAgainstNotFoundExtensions.cs | 14 --- .../GuardAgainstNullExtensions.cs | 57 ----------- .../GuardAgainstOutOfRangeExtensions.cs | 37 ------- .../GuardAgainstStringLengthExtensions.cs | 16 --- .../GuardAgainstZeroExtensions.cs | 41 -------- 8 files changed, 5 insertions(+), 272 deletions(-) diff --git a/src/GuardClauses/CompilerFixes/CallerArgumentExpressionAttribute.cs b/src/GuardClauses/CompilerFixes/CallerArgumentExpressionAttribute.cs index b8bc2296..8d15180f 100644 --- a/src/GuardClauses/CompilerFixes/CallerArgumentExpressionAttribute.cs +++ b/src/GuardClauses/CompilerFixes/CallerArgumentExpressionAttribute.cs @@ -1,4 +1,4 @@ -#if NETSTANDARD2_1 +#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER namespace System.Runtime.CompilerServices; diff --git a/src/GuardClauses/GuardAgainstExpressionExtensions.cs b/src/GuardClauses/GuardAgainstExpressionExtensions.cs index d6464b6b..0f679ed1 100644 --- a/src/GuardClauses/GuardAgainstExpressionExtensions.cs +++ b/src/GuardClauses/GuardAgainstExpressionExtensions.cs @@ -23,10 +23,8 @@ public static T Expression(this IGuardClause guardClause, Func 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)) { @@ -53,10 +51,8 @@ public static async Task ExpressionAsync(this IGuardClause guardClause, Func> 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)) { diff --git a/src/GuardClauses/GuardAgainstNegativeExtensions.cs b/src/GuardClauses/GuardAgainstNegativeExtensions.cs index 8ebc2d38..503fdfad 100644 --- a/src/GuardClauses/GuardAgainstNegativeExtensions.cs +++ b/src/GuardClauses/GuardAgainstNegativeExtensions.cs @@ -14,17 +14,10 @@ public static partial class GuardClauseExtensions /// Optional. Custom error message /// if the value is not negative. /// -#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(guardClause, input, parameterName, message); } @@ -38,17 +31,10 @@ public static int Negative(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not negative. /// -#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(guardClause, input, parameterName, message); } @@ -62,17 +48,10 @@ public static long Negative(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not negative. /// -#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(guardClause, input, parameterName, message); } @@ -86,17 +65,10 @@ public static decimal Negative(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not negative. /// -#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(guardClause, input, parameterName, message); } @@ -110,17 +82,10 @@ public static float Negative(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not negative. /// -#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(guardClause, input, parameterName, message); } @@ -134,17 +99,10 @@ public static double Negative(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not negative. /// -#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(guardClause, input, parameterName, message); } @@ -158,17 +116,10 @@ public static TimeSpan Negative(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not negative. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - private static T Negative(this IGuardClause guardClause, - T input, - string parameterName, - string? message = null) where T : struct, IComparable -#else private static T Negative(this IGuardClause guardClause, T input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) where T : struct, IComparable -#endif { if (input.CompareTo(default(T)) < 0) { @@ -186,17 +137,10 @@ private static T Negative(this IGuardClause guardClause, /// /// Optional. Custom error message /// if the value is not negative or zero. -#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(guardClause, input, parameterName, message); } @@ -209,17 +153,10 @@ public static int NegativeOrZero(this IGuardClause guardClause, /// /// Optional. Custom error message /// if the value is not negative or zero. -#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(guardClause, input, parameterName, message); } @@ -232,17 +169,10 @@ public static long NegativeOrZero(this IGuardClause guardClause, /// /// Optional. Custom error message /// if the value is not negative or zero. -#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(guardClause, input, parameterName, message); } @@ -255,17 +185,10 @@ public static decimal NegativeOrZero(this IGuardClause guardClause, /// /// Optional. Custom error message /// if the value is not negative or zero. -#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(guardClause, input, parameterName, message); } @@ -278,17 +201,10 @@ public static float NegativeOrZero(this IGuardClause guardClause, /// /// Optional. Custom error message /// if the value is not negative or zero. -#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(guardClause, input, parameterName, message); } @@ -301,17 +217,10 @@ public static double NegativeOrZero(this IGuardClause guardClause, /// /// Optional. Custom error message /// if the value is not negative or zero. -#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(guardClause, input, parameterName, message); } @@ -325,17 +234,10 @@ public static TimeSpan NegativeOrZero(this IGuardClause guardClause, /// /// Optional. Custom error message /// if the value is not negative or zero. -#if NETFRAMEWORK || NETSTANDARD2_0 - private static T NegativeOrZero(this IGuardClause guardClause, - T input, - string parameterName, - string? message = null) where T : struct, IComparable -#else private static T NegativeOrZero(this IGuardClause guardClause, T input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) where T : struct, IComparable -#endif { if (input.CompareTo(default(T)) <= 0) { diff --git a/src/GuardClauses/GuardAgainstNotFoundExtensions.cs b/src/GuardClauses/GuardAgainstNotFoundExtensions.cs index 28c4425d..3594a90d 100644 --- a/src/GuardClauses/GuardAgainstNotFoundExtensions.cs +++ b/src/GuardClauses/GuardAgainstNotFoundExtensions.cs @@ -15,17 +15,10 @@ public static partial class GuardClauseExtensions /// /// if the value is not null. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static T NotFound(this IGuardClause guardClause, - [NotNull][ValidatedNotNull] string key, - [NotNull][ValidatedNotNull] T? input, - string parameterName) -#else public static T NotFound(this IGuardClause guardClause, [NotNull][ValidatedNotNull] string key, [NotNull][ValidatedNotNull] T? input, [CallerArgumentExpression("input")] string? parameterName = null) -#endif { guardClause.NullOrEmpty(key, nameof(key)); @@ -48,17 +41,10 @@ public static T NotFound(this IGuardClause guardClause, /// /// if the value is not null. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static T NotFound(this IGuardClause guardClause, - [NotNull][ValidatedNotNull] TKey key, - [NotNull][ValidatedNotNull] T? input, - string parameterName) where TKey : struct -#else public static T NotFound(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)); diff --git a/src/GuardClauses/GuardAgainstNullExtensions.cs b/src/GuardClauses/GuardAgainstNullExtensions.cs index e1213121..9a8fbd1a 100644 --- a/src/GuardClauses/GuardAgainstNullExtensions.cs +++ b/src/GuardClauses/GuardAgainstNullExtensions.cs @@ -23,17 +23,10 @@ public static partial class GuardClauseExtensions /// /// Optional. Custom error message /// if the value is not null. -#if NETFRAMEWORK || NETSTANDARD2_0 - public static T Null(this IGuardClause guardClause, - [NotNull][ValidatedNotNull] T? input, - string parameterName, - string? message = null) -#else public static T Null(this IGuardClause guardClause, [NotNull][ValidatedNotNull]T? input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { if (input is null) { @@ -56,17 +49,10 @@ public static T Null(this IGuardClause guardClause, /// /// Optional. Custom error message /// if the value is not null. -#if NETFRAMEWORK || NETSTANDARD2_0 - public static T Null(this IGuardClause guardClause, - [NotNull][ValidatedNotNull] T? input, - string parameterName, - string? message = null) where T : struct -#else public static T Null(this IGuardClause guardClause, [NotNull][ValidatedNotNull]T? input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) where T : struct -#endif { if (input is null) { @@ -91,17 +77,10 @@ public static T Null(this IGuardClause guardClause, /// if the value is not an empty string or null. /// /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static string NullOrEmpty(this IGuardClause guardClause, - [NotNull][ValidatedNotNull] string? input, - string parameterName, - string? message = null) -#else public static string NullOrEmpty(this IGuardClause guardClause, [NotNull][ValidatedNotNull] string? input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { Guard.Against.Null(input, parameterName, message); if (input == string.Empty) @@ -123,17 +102,10 @@ public static string NullOrEmpty(this IGuardClause guardClause, /// if the value is not an empty guid or null. /// /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static Guid NullOrEmpty(this IGuardClause guardClause, - [NotNull][ValidatedNotNull] Guid? input, - string parameterName, - string? message = null) -#else public static Guid NullOrEmpty(this IGuardClause guardClause, [NotNull][ValidatedNotNull] Guid? input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { Guard.Against.Null(input, parameterName, message); if (input == Guid.Empty) @@ -155,17 +127,10 @@ public static Guid NullOrEmpty(this IGuardClause guardClause, /// if the value is not an empty enumerable or null. /// /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static IEnumerable NullOrEmpty(this IGuardClause guardClause, - [NotNull][ValidatedNotNull] IEnumerable? input, - string parameterName, - string? message = null) -#else public static IEnumerable NullOrEmpty(this IGuardClause guardClause, [NotNull][ValidatedNotNull] IEnumerable? input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { Guard.Against.Null(input, parameterName, message); @@ -192,17 +157,10 @@ public static IEnumerable NullOrEmpty(this IGuardClause guardClause, /// if the value is not an empty or whitespace string. /// /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static string NullOrWhiteSpace(this IGuardClause guardClause, - [NotNull][ValidatedNotNull] string? input, - string parameterName, - string? message = null) -#else public static string NullOrWhiteSpace(this IGuardClause guardClause, [NotNull][ValidatedNotNull] string? input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { Guard.Against.NullOrEmpty(input, parameterName, message); if (String.IsNullOrWhiteSpace(input)) @@ -222,17 +180,10 @@ public static string NullOrWhiteSpace(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not default for that type. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static T Default(this IGuardClause guardClause, - [AllowNull, NotNull] T input, - string parameterName, - string? message = null) -#else public static T Default(this IGuardClause guardClause, [AllowNull, NotNull]T input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { if (EqualityComparer.Default.Equals(input, default(T)!) || input is null) { @@ -256,19 +207,11 @@ public static T Default(this IGuardClause guardClause, /// /// /// -#if NETFRAMEWORK || NETSTANDARD2_0 public static T NullOrInvalidInput(this IGuardClause guardClause, [NotNull] T? input, string parameterName, Func predicate, string? message = null) -#else - public static T NullOrInvalidInput(this IGuardClause guardClause, - [NotNull] T? input, - string parameterName, - Func predicate, - string? message = null) -#endif { Guard.Against.Null(input, parameterName, message); diff --git a/src/GuardClauses/GuardAgainstOutOfRangeExtensions.cs b/src/GuardClauses/GuardAgainstOutOfRangeExtensions.cs index 06da4e2c..704de6d2 100644 --- a/src/GuardClauses/GuardAgainstOutOfRangeExtensions.cs +++ b/src/GuardClauses/GuardAgainstOutOfRangeExtensions.cs @@ -21,21 +21,12 @@ public static partial class GuardClauseExtensions /// Optional. Custom error message /// if the value is not negative. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static string LengthOutOfRange(this IGuardClause guardClause, - string input, - int minLength, - int maxLength, - string parameterName, - string? message = null) -#else public static string LengthOutOfRange(this IGuardClause guardClause, string input, int minLength, int maxLength, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { Guard.Against.Negative(maxLength - minLength, parameterName: "min or max length", message: "Min length must be equal or less than max length."); @@ -55,17 +46,10 @@ public static string LengthOutOfRange(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not out of range. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static int EnumOutOfRange(this IGuardClause guardClause, - int input, - string parameterName, - string? message = null) where T : struct, Enum -#else public static int EnumOutOfRange(this IGuardClause guardClause, int input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) where T : struct, Enum -#endif { if (!Enum.IsDefined(typeof(T), input)) { @@ -89,17 +73,10 @@ public static int EnumOutOfRange(this IGuardClause guardClause, /// /// Optional. Custom error message /// if the value is not out of range. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static T EnumOutOfRange(this IGuardClause guardClause, - T input, - string parameterName, - string? message = null) where T : struct, Enum -#else public static T EnumOutOfRange(this IGuardClause guardClause, T input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) where T : struct, Enum -#endif { if (!Enum.IsDefined(typeof(T), input)) { @@ -159,17 +136,10 @@ public static IEnumerable OutOfRange(this IGuardClause guardClause, /// if the value is in the range of valid SqlDateTime values. /// /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static DateTime NullOrOutOfSQLDateRange(this IGuardClause guardClause, - [NotNull][ValidatedNotNull] DateTime? input, - string parameterName, - string? message = null) -#else public static DateTime NullOrOutOfSQLDateRange(this IGuardClause guardClause, [NotNull][ValidatedNotNull] DateTime? input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { guardClause.Null(input, nameof(input)); return OutOfSQLDateRange(guardClause, input.Value, parameterName, message); @@ -184,17 +154,10 @@ public static DateTime NullOrOutOfSQLDateRange(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is in the range of valid SqlDateTime values. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static DateTime OutOfSQLDateRange(this IGuardClause guardClause, - DateTime input, - string parameterName, - string? message = null) -#else public static DateTime OutOfSQLDateRange(this IGuardClause guardClause, DateTime input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { // System.Data is unavailable in .NET Standard so we can't use SqlDateTime. const long sqlMinDateTicks = 552877920000000000; diff --git a/src/GuardClauses/GuardAgainstStringLengthExtensions.cs b/src/GuardClauses/GuardAgainstStringLengthExtensions.cs index 689862fd..39083f85 100644 --- a/src/GuardClauses/GuardAgainstStringLengthExtensions.cs +++ b/src/GuardClauses/GuardAgainstStringLengthExtensions.cs @@ -20,19 +20,11 @@ public static partial class GuardClauseExtensions /// Optional. Custom error message /// if the value is not negative. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static string StringTooShort(this IGuardClause guardClause, - string input, - int minLength, - string parameterName, - string? message = null) -#else public static string StringTooShort(this IGuardClause guardClause, string input, int minLength, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { Guard.Against.NegativeOrZero(minLength, nameof(minLength)); if (input.Length < minLength) @@ -52,19 +44,11 @@ public static string StringTooShort(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not negative. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static string StringTooLong(this IGuardClause guardClause, - string input, - int maxLength, - string parameterName, - string? message = null) -#else public static string StringTooLong(this IGuardClause guardClause, string input, int maxLength, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { Guard.Against.NegativeOrZero(maxLength, nameof(maxLength)); if (input.Length > maxLength) diff --git a/src/GuardClauses/GuardAgainstZeroExtensions.cs b/src/GuardClauses/GuardAgainstZeroExtensions.cs index 195d5279..b2720e61 100644 --- a/src/GuardClauses/GuardAgainstZeroExtensions.cs +++ b/src/GuardClauses/GuardAgainstZeroExtensions.cs @@ -15,17 +15,10 @@ public static partial class GuardClauseExtensions /// Optional. Custom error message /// if the value is not zero. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static int Zero(this IGuardClause guardClause, - int input, - string parameterName, - string? message = null) -#else public static int Zero(this IGuardClause guardClause, int input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { return Zero(guardClause, input, parameterName!, message); } @@ -39,17 +32,10 @@ public static int Zero(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not zero. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static long Zero(this IGuardClause guardClause, - long input, - string parameterName, - string? message = null) -#else public static long Zero(this IGuardClause guardClause, long input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { return Zero(guardClause, input, parameterName!, message); } @@ -63,17 +49,10 @@ public static long Zero(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not zero. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static decimal Zero(this IGuardClause guardClause, - decimal input, - string parameterName, - string? message = null) -#else public static decimal Zero(this IGuardClause guardClause, decimal input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { return Zero(guardClause, input, parameterName!, message); } @@ -87,17 +66,10 @@ public static decimal Zero(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not zero. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static float Zero(this IGuardClause guardClause, - float input, - string parameterName, - string? message = null) -#else public static float Zero(this IGuardClause guardClause, float input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { return Zero(guardClause, input, parameterName!, message); } @@ -111,17 +83,10 @@ public static float Zero(this IGuardClause guardClause, /// Optional. Custom error message /// if the value is not zero. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static double Zero(this IGuardClause guardClause, - double input, - string parameterName, - string? message = null) -#else public static double Zero(this IGuardClause guardClause, double input, [CallerArgumentExpression("input")] string? parameterName = null, string? message = null) -#endif { return Zero(guardClause, input, parameterName!, message); } @@ -134,15 +99,9 @@ public static double Zero(this IGuardClause guardClause, /// /// if the value is not zero. /// -#if NETFRAMEWORK || NETSTANDARD2_0 - public static TimeSpan Zero(this IGuardClause guardClause, - TimeSpan input, - string parameterName) -#else public static TimeSpan Zero(this IGuardClause guardClause, TimeSpan input, [CallerArgumentExpression("input")] string? parameterName = null) -#endif { return Zero(guardClause, input, parameterName!); } From 76a6a4de90a074caf4ac0f613a37eaae3f40919f Mon Sep 17 00:00:00 2001 From: Rudi Larno Date: Mon, 26 Feb 2024 18:12:31 +0100 Subject: [PATCH 2/3] Update for Guard Against StringLength (#343) * Update GuardAgainstStringLengthExtensions.cs Namespace and Maxmimum typo * Remove using statement --- src/GuardClauses/GuardAgainstStringLengthExtensions.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/GuardClauses/GuardAgainstStringLengthExtensions.cs b/src/GuardClauses/GuardAgainstStringLengthExtensions.cs index 39083f85..908f3bf8 100644 --- a/src/GuardClauses/GuardAgainstStringLengthExtensions.cs +++ b/src/GuardClauses/GuardAgainstStringLengthExtensions.cs @@ -1,8 +1,7 @@ using System; using System.Runtime.CompilerServices; -using Ardalis.GuardClauses; -namespace GuardClauses; +namespace Ardalis.GuardClauses; /// /// The class containing extension methods for @@ -53,7 +52,7 @@ public static string StringTooLong(this IGuardClause guardClause, Guard.Against.NegativeOrZero(maxLength, nameof(maxLength)); if (input.Length > maxLength) { - throw new ArgumentException(message ?? $"Input {parameterName} with length {input.Length} is too long. Maxmimum length is {maxLength}.", parameterName); + throw new ArgumentException(message ?? $"Input {parameterName} with length {input.Length} is too long. Maximum length is {maxLength}.", parameterName); } return input; } From 79729ab55098b1c85eaae090492b175cb65a6423 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Mon, 26 Feb 2024 12:15:50 -0500 Subject: [PATCH 3/3] Update GuardClauses.csproj --- src/GuardClauses/GuardClauses.csproj | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/GuardClauses/GuardClauses.csproj b/src/GuardClauses/GuardClauses.csproj index aeaa31c9..a0f504e3 100644 --- a/src/GuardClauses/GuardClauses.csproj +++ b/src/GuardClauses/GuardClauses.csproj @@ -18,13 +18,10 @@ https://github.com/ardalis/guardclauses guard clause clauses assert assertion - * Perf Improvements #328 by mjebrahimi - * StringTooShort #330 - * StringTooLong #332 - * StringLengthOutOfRange #333 - * Compiler Warning Fixes #335 +* Removed different method signatures for NETFRAMEWORK and NETSTANDARD2_0 by @Ergamon in #338 +* Update for Guard Against StringLength by @rlarno in #343 - 4.4.0 + 4.5.0 Ardalis.GuardClauses icon.png true