From 03c6f17c5c08f56464cb7560f694247ccad5ae18 Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Wed, 4 Jun 2025 19:01:31 -0400 Subject: [PATCH 01/11] Closes #31: Remove Sonar issues --- src/Validations/Arguments.cs | 6 +++--- src/Validations/Properties/AssemblyInfo.cs | 10 ---------- .../CompliesWithUsingLambdaMessageFacts.cs | 10 +++++----- .../DoesNotComplyWithMessageFacts.cs | 14 +++++++------- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/Validations/Arguments.cs b/src/Validations/Arguments.cs index 2423d97..7afe975 100644 --- a/src/Validations/Arguments.cs +++ b/src/Validations/Arguments.cs @@ -176,7 +176,7 @@ public static Guid NotEmptyOrExceptionWithMessage(Guid value, : value; } - private static bool IsEmpty(Guid value) => value == default; + private static bool IsEmpty(Guid value) => value == Guid.Empty; #endregion @@ -579,7 +579,7 @@ public static TNullable CompliesWith( [NotNull] string preconditionDescription, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") where TNullable : class - => CompliesWithExpected(value, validator, paramName, preconditionDescription, true); + => CompliesWithExpected(value, validator, preconditionDescription, paramName, true); /// /// Checks the given value for and then if the its complies with the validator function. @@ -597,7 +597,7 @@ public static TNullable DoesNotComplyWith( [NotNull] string preconditionDescription, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") where TNullable : class - => CompliesWithExpected(value, validator, paramName, preconditionDescription, false); + => CompliesWithExpected(value, validator, preconditionDescription, paramName, false); [return: NotNull] private static TNullable CompliesWithExpected( diff --git a/src/Validations/Properties/AssemblyInfo.cs b/src/Validations/Properties/AssemblyInfo.cs index dcd1cc2..4bca29d 100644 --- a/src/Validations/Properties/AssemblyInfo.cs +++ b/src/Validations/Properties/AssemblyInfo.cs @@ -1,13 +1,3 @@ [assembly: CLSCompliant(true)] [assembly: System.Resources.NeutralResourcesLanguage("en")] [assembly: System.Runtime.InteropServices.ComVisible(false)] - -namespace Triplex.Validations.Properties; - -/// -/// Assembly information. -/// -public sealed class AssemblyInfo -{ - -} diff --git a/tests/unit/Validations.Tests/ArgumentsFacts/CompliesWithUsingLambdaMessageFacts.cs b/tests/unit/Validations.Tests/ArgumentsFacts/CompliesWithUsingLambdaMessageFacts.cs index 9569ab1..da093c3 100644 --- a/tests/unit/Validations.Tests/ArgumentsFacts/CompliesWithUsingLambdaMessageFacts.cs +++ b/tests/unit/Validations.Tests/ArgumentsFacts/CompliesWithUsingLambdaMessageFacts.cs @@ -27,8 +27,8 @@ public void Returns_Same_Instance() public void With_False_Throws_ArgumentException() { const string? someString = "Hello World 1234"; - Assert.That(() => Arguments.CompliesWith(someString, val => val.Length > 100, nameof(someString), - PreconditionDescription), + Assert.That(() => Arguments.CompliesWith(someString, val => val.Length > 100, PreconditionDescription, + nameof(someString)), Throws.ArgumentException .With.Property(nameof(ArgumentException.ParamName)).EqualTo(nameof(someString)) .And.Message.Contains(PreconditionDescription)); @@ -40,18 +40,18 @@ public void With_Invalid_ParamName_Throws_ArgumentException([Values(null, "", " { const string? someString = "Hello World 1235"; - Assert.That(() => Arguments.CompliesWith(someString, val => precondition, paramName!, PreconditionDescription), + Assert.That(() => Arguments.CompliesWith(someString, val => precondition, PreconditionDescription, paramName!), Throws.InstanceOf() .With.Property(nameof(ArgumentException.ParamName)).EqualTo("paramName")); } [Test] - public void With_Invalid_Description_ParamName_Throws_ArgumentException( + public void With_Invalid_Description_Throws_ArgumentException( [Values(null, "", " ", "\n\r\t ")] string? description, [Values] bool precondition) { const string? someString = "Hello World 1235"; - Assert.That(() => Arguments.CompliesWith(someString, val => precondition, nameof(someString), description!), + Assert.That(() => Arguments.CompliesWith(someString, val => precondition, description!, nameof(someString)), Throws.InstanceOf() .With.Property(nameof(ArgumentException.ParamName)).EqualTo("preconditionDescription")); } diff --git a/tests/unit/Validations.Tests/ArgumentsFacts/DoesNotComplyWithMessageFacts.cs b/tests/unit/Validations.Tests/ArgumentsFacts/DoesNotComplyWithMessageFacts.cs index c6d96ba..7916701 100644 --- a/tests/unit/Validations.Tests/ArgumentsFacts/DoesNotComplyWithMessageFacts.cs +++ b/tests/unit/Validations.Tests/ArgumentsFacts/DoesNotComplyWithMessageFacts.cs @@ -27,8 +27,8 @@ public void Returns_Same_Instance() public void With_True_Throws_ArgumentException() { const string? someString = "123456789"; - Assert.That(() => Arguments.DoesNotComplyWith(someString, val => val.Length == 9, nameof(someString), - PreconditionDescription), + Assert.That(() => Arguments.DoesNotComplyWith(someString, val => val.Length == 9, PreconditionDescription, + nameof(someString)), Throws.ArgumentException .With.Property(nameof(ArgumentException.ParamName)).EqualTo(nameof(someString)) .And.Message.Contains(PreconditionDescription)); @@ -40,8 +40,8 @@ public void With_Invalid_ParamName_Throws_ArgumentException([Values(null, "", " { const string? someString = "Hello World 1235"; - Assert.That(() => Arguments.DoesNotComplyWith(someString, val => precondition, paramName!, - PreconditionDescription), + Assert.That(() => Arguments.DoesNotComplyWith(someString, val => precondition, + PreconditionDescription, paramName!), Throws.InstanceOf() .With.Property(nameof(ArgumentException.ParamName)).EqualTo("paramName")); } @@ -52,7 +52,7 @@ public void With_Invalid_Description_ParamName_Throws_ArgumentException( { const string? someString = "Hello World 1235"; - Assert.That(() => Arguments.DoesNotComplyWith(someString, val => precondition, nameof(someString), description!), + Assert.That(() => Arguments.DoesNotComplyWith(someString, val => precondition, description!, nameof(someString)), Throws.InstanceOf() .With.Property(nameof(ArgumentException.ParamName)).EqualTo("preconditionDescription")); } @@ -61,8 +61,8 @@ public void With_Invalid_Description_ParamName_Throws_ArgumentException( public void With_Null_Value_Throws_ArgumentNullException() { const string? someString = null; - Assert.That(() => Arguments.DoesNotComplyWith(someString, val => val.Length > 100, nameof(someString), - PreconditionDescription), + Assert.That(() => Arguments.DoesNotComplyWith(someString, val => val.Length > 100, + PreconditionDescription, nameof(someString)), Throws.ArgumentNullException .With.Property(nameof(ArgumentException.ParamName)).EqualTo("value") .And.Message.Contains("cannot be null")); From 11a2e160c911d2f9295658cb4e83c2877b8c7c4f Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Wed, 4 Jun 2025 19:05:44 -0400 Subject: [PATCH 02/11] Only build dotnetcore.yml once per push --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 7cd0a4c..86c0a5b 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -1,7 +1,7 @@ name: .NET Core Tests and CodeQL Security Analysis on: - [ push, pull_request ] + [ pull_request ] jobs: build: From e0b2389f02735a1ae4c92e5400bf80dfa1f7954f Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Thu, 5 Jun 2025 21:39:28 -0400 Subject: [PATCH 03/11] Removing sonar issues --- .../ArgumentsHelpers/OutOfRangeChecks.cs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs b/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs index 0caf3df..271d3a1 100644 --- a/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs +++ b/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs @@ -8,7 +8,7 @@ internal static TComparable LessThan([NotNull] TComparable? value, where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMaxExclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull(nameof(other)))); + SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); return CheckBoundaries(value, range, paramName, null); } @@ -18,9 +18,9 @@ internal static TComparable LessThan([NotNull] TComparable? value, [NotNull] string customMessage) where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMaxExclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull(nameof(other)))); + SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); - return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull(nameof(customMessage))); + return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull()); } [return: NotNull] @@ -29,7 +29,7 @@ internal static TComparable LessThanOrEqualTo([NotNull] TComparable where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMaxInclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull(nameof(other)))); + SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); return CheckBoundaries(value, range, paramName, null); } @@ -41,9 +41,9 @@ internal static TComparable LessThanOrEqualTo([NotNull] TComparable where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMaxInclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull(nameof(other)))); + SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); - return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull(nameof(customMessage))); + return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull()); } [return: NotNull] @@ -52,7 +52,7 @@ internal static TComparable GreaterThan([NotNull] TComparable? valu where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMinExclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull(nameof(other)))); + SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); return CheckBoundaries(value, range, paramName, null); } @@ -63,9 +63,9 @@ internal static TComparable GreaterThan([NotNull] TComparable? valu [NotNull] string customMessage) where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMinExclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull(nameof(other)))); + SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); - return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull(nameof(customMessage))); + return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull()); } [return: NotNull] @@ -74,7 +74,7 @@ internal static TComparable GreaterThanOrEqualTo([NotNull] TCompara where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMinInclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull(nameof(other)))); + SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); return CheckBoundaries(value, range, paramName, null); } @@ -85,9 +85,9 @@ internal static TComparable GreaterThanOrEqualTo([NotNull] TCompara [NotNull] string customMessage) where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMinInclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull(nameof(other)))); + SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); - return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull(nameof(customMessage))); + return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull()); } [return: NotNull] @@ -119,13 +119,13 @@ internal static TComparable Between( [NotNull] string customMessage) where TComparable : IComparable { ComparableRange range = new( - SimpleOption.SomeNotNull(fromInclusive.ValueOrThrowIfNull(nameof(fromInclusive))), - SimpleOption.SomeNotNull(toInclusive.ValueOrThrowIfNull(nameof(toInclusive)))); + SimpleOption.SomeNotNull(fromInclusive.ValueOrThrowIfNull()), + SimpleOption.SomeNotNull(toInclusive.ValueOrThrowIfNull())); return range.Contains( - value.ValueOrThrowIfNull(nameof(value)), - paramName.ValueOrThrowIfNull(nameof(customMessage)), - customMessage.ValueOrThrowIfNull(nameof(customMessage))); + value.ValueOrThrowIfNull(), + paramName.ValueOrThrowIfNull(), + customMessage.ValueOrThrowIfNull()); } @@ -136,7 +136,7 @@ private static TComparable CheckBoundaries( [NotNull] string paramName, string? customMessage) where TComparable : IComparable => range.Contains( - value.ValueOrThrowIfNull(nameof(value)), - paramName.ValueOrThrowIfNull(nameof(paramName)), + value.ValueOrThrowIfNull(), + paramName.ValueOrThrowIfNull(), customMessage); } From 6f7374511dcc29abed00684942b5d97944795b5b Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Thu, 5 Jun 2025 21:56:22 -0400 Subject: [PATCH 04/11] Removing Sonar issues --- src/Validations/ArgumentsHelpers/NullAndEmptyChecks.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Validations/ArgumentsHelpers/NullAndEmptyChecks.cs b/src/Validations/ArgumentsHelpers/NullAndEmptyChecks.cs index 57263fb..87fc0cd 100644 --- a/src/Validations/ArgumentsHelpers/NullAndEmptyChecks.cs +++ b/src/Validations/ArgumentsHelpers/NullAndEmptyChecks.cs @@ -5,14 +5,14 @@ internal static class NullAndEmptyChecks [return: NotNull] internal static TParamType NotNull([NotNull] TParamType? value, [NotNull] string paramName) where TParamType : class - => value.ValueOrThrowIfNull(paramName.ValueOrThrowIfNull(nameof(paramName))); + => value.ValueOrThrowIfNull(paramName.ValueOrThrowIfNull()); [return: NotNull] internal static TParamType NotNull([NotNull] TParamType? value, [NotNull] string paramName, [NotNull] string customMessage) where TParamType : class - => value.ValueOrThrowIfNull(paramName.ValueOrThrowIfNull(nameof(paramName)), - customMessage.ValueOrThrowIfNull(nameof(customMessage))); + => value.ValueOrThrowIfNull(paramName.ValueOrThrowIfNull(), + customMessage.ValueOrThrowIfNull()); [return: NotNull] internal static string NotNullEmptyOrWhiteSpaceOnly([NotNull] string? value, From 84a248bad7f7bf067e55282532737c491d50871b Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Thu, 5 Jun 2025 22:00:26 -0400 Subject: [PATCH 05/11] Version bump --- src/Validations/Validations.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Validations/Validations.csproj b/src/Validations/Validations.csproj index 2b1f1ee..1390452 100644 --- a/src/Validations/Validations.csproj +++ b/src/Validations/Validations.csproj @@ -1,6 +1,6 @@  - 4.0.0 + 4.1.0 preview net9.0 From 87af35dda8abcd1759c1e17c535e5d7c45fffc9f Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Fri, 6 Jun 2025 07:13:51 -0400 Subject: [PATCH 06/11] Refactor Extensions --- .../Algorithms/Checksum/LuhnFormula.cs | 2 +- src/Validations/Arguments.cs | 32 ++++---- .../ArgumentsHelpers/Extensions.cs | 76 ++++++++++++------- .../ArgumentsHelpers/NullAndEmptyChecks.cs | 42 +++++----- .../ArgumentsHelpers/OutOfRangeChecks.cs | 46 +++++------ .../Exceptions/ArgumentFormatException.cs | 2 +- src/Validations/State.cs | 12 +-- 7 files changed, 117 insertions(+), 95 deletions(-) diff --git a/src/Validations/Algorithms/Checksum/LuhnFormula.cs b/src/Validations/Algorithms/Checksum/LuhnFormula.cs index 96207f5..758178d 100644 --- a/src/Validations/Algorithms/Checksum/LuhnFormula.cs +++ b/src/Validations/Algorithms/Checksum/LuhnFormula.cs @@ -66,7 +66,7 @@ public static bool IsValid([NotNull] string? fullDigits) [return: NotNull] private static string ValidateDigitsAsString([NotNull] string? fullDigits) { - string notNullDigits = fullDigits.ValueOrThrowIfNullOrZeroLength(nameof(fullDigits)); + string notNullDigits = fullDigits.CheckNotZeroLength(nameof(fullDigits)); return notNullDigits.Length switch { diff --git a/src/Validations/Arguments.cs b/src/Validations/Arguments.cs index 7afe975..c26c135 100644 --- a/src/Validations/Arguments.cs +++ b/src/Validations/Arguments.cs @@ -25,7 +25,7 @@ public static partial class Arguments public static TParamType OrException( [NotNull] TParamType? value, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") where TParamType : class - => NullAndEmptyChecks.NotNull(value, paramName); + => NullAndEmptyChecks.Check(value, paramName); /// /// Checks that the provided value is not . @@ -52,7 +52,7 @@ public static TParamType OrExceptionWithMessage( [NotNull] string customMessage, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") where TParamType : class - => NullAndEmptyChecks.NotNull(value, paramName, customMessage); + => NullAndEmptyChecks.Check(value, paramName, customMessage); /// /// Checks that the provided value is not , empty (zero length), or contains white-space @@ -123,7 +123,7 @@ public static string NotEmptyOrException( public static Guid NotEmptyOrException(Guid value, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { - string validParamName = paramName.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(); + string validParamName = paramName.CheckNotZeroLengthOrWhiteSpaceOnly(); return IsEmpty(value) ? throw new ArgumentException(validParamName) : value; } @@ -168,8 +168,8 @@ public static Guid NotEmptyOrExceptionWithMessage(Guid value, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { (string validParamName, string validCustomMessage) = - (paramName.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(), - customMessage.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly()); + (paramName.CheckNotZeroLengthOrWhiteSpaceOnly(), + customMessage.CheckNotZeroLengthOrWhiteSpaceOnly()); return IsEmpty(value) ? throw new ArgumentException(paramName: validParamName, message: validCustomMessage) @@ -480,10 +480,10 @@ public static string ValidLuhnChecksum([NotNull] string? value, [NotNull] string [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { (string validParamName, string validCustomMessage) = - (paramName.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(), - customMessage.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly()); + (paramName.CheckNotZeroLengthOrWhiteSpaceOnly(), + customMessage.CheckNotZeroLengthOrWhiteSpaceOnly()); - string notNullValue = NullAndEmptyChecks.NotNull(value, validParamName); + string notNullValue = NullAndEmptyChecks.Check(value, validParamName); ValidateLuhnSequenceFormat(notNullValue, validCustomMessage); @@ -522,9 +522,9 @@ private static int[] ToDigitsArray(string notNullValue) public static string ValidBase64([NotNull] string? value, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { string validParamName = - paramName.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(); + paramName.CheckNotZeroLengthOrWhiteSpaceOnly(); - string notNullValue = value.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(validParamName); + string notNullValue = value.CheckNotZeroLengthOrWhiteSpaceOnly(validParamName); return IsBase64String(notNullValue) ? notNullValue : throw new FormatException($"{validParamName} is not a valid Base64 String."); @@ -544,8 +544,8 @@ public static string ValidBase64([NotNull] string? value, [NotNull] string custo [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { (string validParamName, string validCustomMessage) = - (paramName.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(), - customMessage.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly()); + (paramName.CheckNotZeroLengthOrWhiteSpaceOnly(), + customMessage.CheckNotZeroLengthOrWhiteSpaceOnly()); string notNullValue = value.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(validParamName, validCustomMessage); @@ -607,11 +607,11 @@ private static TNullable CompliesWithExpected( [NotNull] string paramName, bool expected) where TNullable : class { - TNullable notNullValue = value.ValueOrThrowIfNull(nameof(value)); - Func notNullValidator = validator.ValueOrThrowIfNull(); - string notNullParamName = paramName.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(); + TNullable notNullValue = value.Check(nameof(value)); + Func notNullValidator = validator.Check(); + string notNullParamName = paramName.CheckNotZeroLengthOrWhiteSpaceOnly(); string notNullPreconditionDescription - = preconditionDescription.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(); + = preconditionDescription.CheckNotZeroLengthOrWhiteSpaceOnly(); return notNullValidator(notNullValue) != expected ? throw new ArgumentException(paramName: notNullParamName, message: notNullPreconditionDescription) diff --git a/src/Validations/ArgumentsHelpers/Extensions.cs b/src/Validations/ArgumentsHelpers/Extensions.cs index a8ec4f1..2c7bc17 100644 --- a/src/Validations/ArgumentsHelpers/Extensions.cs +++ b/src/Validations/ArgumentsHelpers/Extensions.cs @@ -6,66 +6,64 @@ namespace Triplex.Validations.ArgumentsHelpers; internal static class Extensions { [return: NotNull] - internal static T ValueOrThrowIfNull([NotNull] this T? value, + internal static T Check([NotNull] this T? value, [CallerArgumentExpression(nameof(value))] string paramName = "") => value ?? throw new ArgumentNullException(paramName); [return: NotNull] - internal static T ValueOrThrowIfNull([NotNull] this T? value, string paramName, string customMessage) + internal static T CheckWithParamName([NotNull] this T? value, string paramName) + => value ?? throw new ArgumentNullException(paramName); + + [return: NotNull] + internal static T CheckWithParamName([NotNull] this T? value, string paramName, string customMessage) => value ?? throw new ArgumentNullException(paramName, customMessage); [return: NotNull] - internal static T ValueOrThrowInvalidOperationIfNull([NotNull] this T? stateElement, + internal static T CheckOrInvalidOperationException([NotNull] this T? stateElement, string elementName) => stateElement ?? throw new InvalidOperationException($"Operation not allowed when {elementName} is null."); [return: NotNull] - internal static string ValueOrThrowIfZeroLength(this string value, string paramName) - => ValueOrThrowIfZeroLength(value, paramName, "Can not be empty (zero length)."); + internal static string CheckNotZeroLength([NotNull] this string? value, [CallerArgumentExpression(nameof(value))] string paramName = "") + => CheckWithParamName(value, paramName) + .DoCheckNotZeroLength(paramName, "Can not be empty (zero length)."); + + [return: NotNull] + internal static string CheckNotZeroLength([NotNull] this string? value, string paramName, string customMessage) + => CheckWithParamName(value, paramName, customMessage) + .DoCheckNotZeroLength(paramName, customMessage); [return: NotNull] - internal static string ValueOrThrowIfZeroLength(this string value, string paramName, string customMessage) + private static string DoCheckNotZeroLength(this string value, string paramName, string customMessage) => value.Length is not 0 ? value : throw new ArgumentFormatException(paramName: paramName, message: customMessage); [return: NotNull] - internal static string ValueOrThrowIfWhiteSpaceOnly(this string value, string paramName) - => ValueOrThrowIfWhiteSpaceOnly(value, paramName, "Can not be white-space only."); + internal static string CheckNotWhiteSpaceOnly(this string value, string paramName) + => CheckNotWhiteSpaceOnly(value, paramName, "Can not be white-space only."); [return: NotNull] - internal static string ValueOrThrowIfWhiteSpaceOnly(this string value, string paramName, string customMessage) + internal static string CheckNotWhiteSpaceOnly(this string value, string paramName, string customMessage) => value.Any(ch => ch.IsNotWhiteSpace()) ? value : throw new ArgumentFormatException(paramName: paramName, message: customMessage); [return: NotNull] - internal static string ValueOrThrowIfNullOrZeroLength([NotNull] this string? value, - string paramName) - => ValueOrThrowIfNull(value, paramName) - .ValueOrThrowIfZeroLength(paramName); - - [return: NotNull] - internal static string ValueOrThrowIfNullOrZeroLength([NotNull] this string? value, - string paramName, string customMessage) - => ValueOrThrowIfNull(value, paramName, customMessage) - .ValueOrThrowIfZeroLength(paramName, customMessage); - - [return: NotNull] - internal static string ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly( + internal static string CheckNotZeroLengthOrWhiteSpaceOnly( [NotNull] this string? value, [CallerArgumentExpression(nameof(value))] string paramName = "") - => ValueOrThrowIfNull(value, paramName) - .ValueOrThrowIfZeroLength(paramName) - .ValueOrThrowIfWhiteSpaceOnly(paramName); + => Check(value, paramName) + .CheckNotZeroLength(paramName) + .CheckNotWhiteSpaceOnly(paramName); [return: NotNull] internal static string ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly([NotNull] this string? value, string paramName, string customMessage) - => ValueOrThrowIfNull(value, paramName, customMessage) - .ValueOrThrowIfZeroLength(paramName, customMessage) - .ValueOrThrowIfWhiteSpaceOnly(paramName, customMessage); + => CheckWithParamName(value, paramName, customMessage) + .DoCheckNotZeroLength(paramName, customMessage) + .CheckNotWhiteSpaceOnly(paramName, customMessage); internal static bool IsNotWhiteSpace(this char ch) => !char.IsWhiteSpace(ch); @@ -97,9 +95,29 @@ internal static TEnumType ValueOrThrowIfNotDefined(this TEnumType val internal static TType[] ValueOrThrowIfNullOrWithLessThanElements( [NotNull] this TType[]? value, int minimumElements, string paramName) { - _ = OutOfRangeChecks.GreaterThanOrEqualTo(ValueOrThrowIfNull(value, paramName).Length, minimumElements, paramName); + _ = OutOfRangeChecks.GreaterThanOrEqualTo(Check(value, paramName).Length, minimumElements, paramName); return value!; } + + #region ParameterName and Exception Messages Helpers + + [return: NotNull] + internal static string CheckParamName( + [NotNull] this string? value, + [CallerArgumentExpression(nameof(value))] string paramName = "") + => CheckWithParamName(value, paramName) + .CheckNotZeroLength(paramName) + .CheckNotWhiteSpaceOnly(paramName); + + [return: NotNull] + internal static string CheckExceptionMessage( + [NotNull] this string? value, + [CallerArgumentExpression(nameof(value))] string paramName = "") + => CheckWithParamName(value, paramName) + .CheckNotZeroLength(paramName) + .CheckNotWhiteSpaceOnly(paramName); + + #endregion } #pragma warning restore CA1303 // Do not pass literals as localized parameters \ No newline at end of file diff --git a/src/Validations/ArgumentsHelpers/NullAndEmptyChecks.cs b/src/Validations/ArgumentsHelpers/NullAndEmptyChecks.cs index 87fc0cd..1e420e9 100644 --- a/src/Validations/ArgumentsHelpers/NullAndEmptyChecks.cs +++ b/src/Validations/ArgumentsHelpers/NullAndEmptyChecks.cs @@ -1,41 +1,45 @@ namespace Triplex.Validations.ArgumentsHelpers; +/// +/// Provides methods to validate that parameters are not null, empty, or whitespace. +/// These methods throw exceptions if the checks fail, ensuring that the parameters meet the expected criteria. +/// This class is intended for internal use within the Triplex library and should not be used directly by consumers. +/// +/// +/// As a general design principle, all checks begin with a check. +/// internal static class NullAndEmptyChecks { [return: NotNull] - internal static TParamType NotNull([NotNull] TParamType? value, - [NotNull] string paramName) where TParamType : class - => value.ValueOrThrowIfNull(paramName.ValueOrThrowIfNull()); + internal static TParamType Check([NotNull] TParamType? value, [NotNull] string paramName) + where TParamType : class + => value.CheckWithParamName(paramName.CheckParamName()); [return: NotNull] - internal static TParamType NotNull([NotNull] TParamType? value, - [NotNull] string paramName, [NotNull] string customMessage) + internal static TParamType Check([NotNull] TParamType? value, [NotNull] string paramName, [NotNull] string customMessage) where TParamType : class - => value.ValueOrThrowIfNull(paramName.ValueOrThrowIfNull(), - customMessage.ValueOrThrowIfNull()); + => value.CheckWithParamName(paramName.CheckParamName(), customMessage.CheckExceptionMessage()); [return: NotNull] - internal static string NotNullEmptyOrWhiteSpaceOnly([NotNull] string? value, - [NotNull] string paramName) - => NotNullOrEmpty(value, paramName.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly()) - .ValueOrThrowIfWhiteSpaceOnly(paramName); + internal static string NotNullEmptyOrWhiteSpaceOnly([NotNull] string? value, [NotNull] string paramName) + => NotNullOrEmpty(value, paramName.CheckParamName()) + .CheckNotWhiteSpaceOnly(paramName); [return: NotNull] internal static string NotNullEmptyOrWhiteSpaceOnly([NotNull] string? value, [NotNull] string paramName, [NotNull] string customMessage) => NotNullOrEmpty(value, paramName, customMessage) - .ValueOrThrowIfWhiteSpaceOnly(paramName, customMessage); + .CheckNotWhiteSpaceOnly(paramName, customMessage); [return: NotNull] - internal static string NotNullOrEmpty([NotNull] string? value, - [NotNull] string paramName) - => value.ValueOrThrowIfNullOrZeroLength( - paramName.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly()); + internal static string NotNullOrEmpty([NotNull] string? value, [NotNull] string paramName) + => value.CheckNotZeroLength( + paramName.CheckParamName()); [return: NotNull] internal static string NotNullOrEmpty([NotNull] string? value, [NotNull] string paramName, [NotNull] string customMessage) - => value.ValueOrThrowIfNullOrZeroLength( - paramName.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(), - customMessage.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly()); + => value.CheckNotZeroLength( + paramName.CheckParamName(), + customMessage.CheckExceptionMessage()); } diff --git a/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs b/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs index 271d3a1..c0f848b 100644 --- a/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs +++ b/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs @@ -8,7 +8,7 @@ internal static TComparable LessThan([NotNull] TComparable? value, where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMaxExclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(other.Check())); return CheckBoundaries(value, range, paramName, null); } @@ -18,9 +18,9 @@ internal static TComparable LessThan([NotNull] TComparable? value, [NotNull] string customMessage) where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMaxExclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(other.Check())); - return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull()); + return CheckBoundaries(value, range, paramName, customMessage.CheckExceptionMessage()); } [return: NotNull] @@ -29,7 +29,7 @@ internal static TComparable LessThanOrEqualTo([NotNull] TComparable where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMaxInclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(other.Check())); return CheckBoundaries(value, range, paramName, null); } @@ -41,9 +41,9 @@ internal static TComparable LessThanOrEqualTo([NotNull] TComparable where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMaxInclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(other.Check())); - return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull()); + return CheckBoundaries(value, range, paramName, customMessage.CheckExceptionMessage()); } [return: NotNull] @@ -52,7 +52,7 @@ internal static TComparable GreaterThan([NotNull] TComparable? valu where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMinExclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(other.Check())); return CheckBoundaries(value, range, paramName, null); } @@ -63,9 +63,9 @@ internal static TComparable GreaterThan([NotNull] TComparable? valu [NotNull] string customMessage) where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMinExclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(other.Check())); - return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull()); + return CheckBoundaries(value, range, paramName, customMessage.CheckExceptionMessage()); } [return: NotNull] @@ -74,7 +74,7 @@ internal static TComparable GreaterThanOrEqualTo([NotNull] TCompara where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMinInclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(other.Check())); return CheckBoundaries(value, range, paramName, null); } @@ -85,9 +85,9 @@ internal static TComparable GreaterThanOrEqualTo([NotNull] TCompara [NotNull] string customMessage) where TComparable : IComparable { ComparableRange range = ComparableRangeFactory.WithMinInclusiveOnly( - SimpleOption.SomeNotNull(other.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(other.Check())); - return CheckBoundaries(value, range, paramName, customMessage.ValueOrThrowIfNull()); + return CheckBoundaries(value, range, paramName, customMessage.CheckExceptionMessage()); } [return: NotNull] @@ -98,13 +98,13 @@ internal static TComparable Between( [NotNull] string paramName) where TComparable : IComparable { ComparableRange range = new( - SimpleOption.SomeNotNull(fromInclusive.ValueOrThrowIfNull()), - SimpleOption.SomeNotNull(toInclusive.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(fromInclusive.Check()), + SimpleOption.SomeNotNull(toInclusive.Check())); - string notNullParamName = paramName.ValueOrThrowIfNull(); + string notNullParamName = paramName.CheckParamName(); return range.Contains( - value.ValueOrThrowIfNull(notNullParamName), + value.Check(notNullParamName), notNullParamName, customMessage: null!); @@ -119,13 +119,13 @@ internal static TComparable Between( [NotNull] string customMessage) where TComparable : IComparable { ComparableRange range = new( - SimpleOption.SomeNotNull(fromInclusive.ValueOrThrowIfNull()), - SimpleOption.SomeNotNull(toInclusive.ValueOrThrowIfNull())); + SimpleOption.SomeNotNull(fromInclusive.Check()), + SimpleOption.SomeNotNull(toInclusive.Check())); return range.Contains( - value.ValueOrThrowIfNull(), - paramName.ValueOrThrowIfNull(), - customMessage.ValueOrThrowIfNull()); + value.Check(), + paramName.CheckParamName(), + customMessage.CheckExceptionMessage()); } @@ -136,7 +136,7 @@ private static TComparable CheckBoundaries( [NotNull] string paramName, string? customMessage) where TComparable : IComparable => range.Contains( - value.ValueOrThrowIfNull(), - paramName.ValueOrThrowIfNull(), + value.Check(), + paramName.CheckParamName(), customMessage); } diff --git a/src/Validations/Exceptions/ArgumentFormatException.cs b/src/Validations/Exceptions/ArgumentFormatException.cs index 05db212..a274c12 100644 --- a/src/Validations/Exceptions/ArgumentFormatException.cs +++ b/src/Validations/Exceptions/ArgumentFormatException.cs @@ -2,7 +2,7 @@ /// /// The exception that is thrown when one of the arguments provided to a method is not valid due to a format -/// problem, usually refering to a or similar. +/// problem, usually referring to a or similar. /// public sealed class ArgumentFormatException : ArgumentException //NOSONAR { diff --git a/src/Validations/State.cs b/src/Validations/State.cs index 51eb9c7..9b45902 100644 --- a/src/Validations/State.cs +++ b/src/Validations/State.cs @@ -19,7 +19,7 @@ public static class State [DebuggerStepThrough] public static void IsTrue(bool stateQuery, [NotNull] string message) { - string notNullMessage = NullAndEmptyChecks.NotNull(message, nameof(message)); + string notNullMessage = NullAndEmptyChecks.Check(message, nameof(message)); if (!stateQuery) { @@ -36,7 +36,7 @@ public static void IsTrue(bool stateQuery, [NotNull] string message) [DebuggerStepThrough] public static void IsFalse(bool stateQuery, [NotNull] string message) { - string notNullMessage = NullAndEmptyChecks.NotNull(message, nameof(message)); + string notNullMessage = NullAndEmptyChecks.Check(message, nameof(message)); if (stateQuery) { @@ -62,9 +62,9 @@ public static T IsNotNull( [NotNull] T stateElement, [NotNull, CallerArgumentExpression(nameof(stateElement))] string elementName = "") { - string notNullElementName = NullAndEmptyChecks.NotNull(elementName, nameof(elementName)); + string notNullElementName = NullAndEmptyChecks.Check(elementName, nameof(elementName)); - return stateElement.ValueOrThrowInvalidOperationIfNull(notNullElementName); + return stateElement.CheckOrInvalidOperationException(notNullElementName); } #endregion //Preconditions @@ -80,7 +80,7 @@ public static T IsNotNull( [DebuggerStepThrough] public static void StillHolds(bool invariant, [NotNull] string message) { - string notNullMessage = NullAndEmptyChecks.NotNull(message, nameof(message)); + string notNullMessage = NullAndEmptyChecks.Check(message, nameof(message)); if (!invariant) { @@ -96,7 +96,7 @@ public static void StillHolds(bool invariant, [NotNull] string message) [DebuggerStepThrough] public static void StillNotHolds(bool invariant, [NotNull] string message) { - string notNullMessage = NullAndEmptyChecks.NotNull(message, nameof(message)); + string notNullMessage = NullAndEmptyChecks.Check(message, nameof(message)); if (invariant) { From 29127af0f849a41a193e2d46a501e06612d94e96 Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Fri, 6 Jun 2025 16:20:12 -0400 Subject: [PATCH 07/11] Fix formatting --- src/Validations/ArgumentsHelpers/Extensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Validations/ArgumentsHelpers/Extensions.cs b/src/Validations/ArgumentsHelpers/Extensions.cs index 2c7bc17..f8c21f2 100644 --- a/src/Validations/ArgumentsHelpers/Extensions.cs +++ b/src/Validations/ArgumentsHelpers/Extensions.cs @@ -109,7 +109,7 @@ internal static string CheckParamName( => CheckWithParamName(value, paramName) .CheckNotZeroLength(paramName) .CheckNotWhiteSpaceOnly(paramName); - + [return: NotNull] internal static string CheckExceptionMessage( [NotNull] this string? value, From 1398d3d8cf11b24f05c5bbf69c8ad1964bc29fba Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Fri, 6 Jun 2025 16:33:49 -0400 Subject: [PATCH 08/11] Removing Sonar issues --- src/Validations/ArgumentsHelpers/Extensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Validations/ArgumentsHelpers/Extensions.cs b/src/Validations/ArgumentsHelpers/Extensions.cs index f8c21f2..014e54a 100644 --- a/src/Validations/ArgumentsHelpers/Extensions.cs +++ b/src/Validations/ArgumentsHelpers/Extensions.cs @@ -25,7 +25,7 @@ internal static T CheckOrInvalidOperationException([NotNull] this T? stateEle ?? throw new InvalidOperationException($"Operation not allowed when {elementName} is null."); [return: NotNull] - internal static string CheckNotZeroLength([NotNull] this string? value, [CallerArgumentExpression(nameof(value))] string paramName = "") + internal static string CheckNotZeroLength([NotNull] this string? value, string paramName) => CheckWithParamName(value, paramName) .DoCheckNotZeroLength(paramName, "Can not be empty (zero length)."); From 26434e915a5bb917eeec42687ad5b6b9ede12395 Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Mon, 9 Jun 2025 22:18:15 -0400 Subject: [PATCH 09/11] Removing build warnings --- src/Validations/Arguments.cs | 21 +++++++++---------- .../ArgumentsHelpers/Extensions.cs | 3 +-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Validations/Arguments.cs b/src/Validations/Arguments.cs index c26c135..b24de5e 100644 --- a/src/Validations/Arguments.cs +++ b/src/Validations/Arguments.cs @@ -123,7 +123,7 @@ public static string NotEmptyOrException( public static Guid NotEmptyOrException(Guid value, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { - string validParamName = paramName.CheckNotZeroLengthOrWhiteSpaceOnly(); + string validParamName = paramName.CheckParamName(); return IsEmpty(value) ? throw new ArgumentException(validParamName) : value; } @@ -168,8 +168,8 @@ public static Guid NotEmptyOrExceptionWithMessage(Guid value, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { (string validParamName, string validCustomMessage) = - (paramName.CheckNotZeroLengthOrWhiteSpaceOnly(), - customMessage.CheckNotZeroLengthOrWhiteSpaceOnly()); + (paramName.CheckParamName(), + customMessage.CheckExceptionMessage()); return IsEmpty(value) ? throw new ArgumentException(paramName: validParamName, message: validCustomMessage) @@ -480,8 +480,8 @@ public static string ValidLuhnChecksum([NotNull] string? value, [NotNull] string [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { (string validParamName, string validCustomMessage) = - (paramName.CheckNotZeroLengthOrWhiteSpaceOnly(), - customMessage.CheckNotZeroLengthOrWhiteSpaceOnly()); + (paramName.CheckParamName(), + customMessage.CheckExceptionMessage()); string notNullValue = NullAndEmptyChecks.Check(value, validParamName); @@ -521,8 +521,7 @@ private static int[] ToDigitsArray(string notNullValue) [DebuggerStepThrough] public static string ValidBase64([NotNull] string? value, [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { - string validParamName = - paramName.CheckNotZeroLengthOrWhiteSpaceOnly(); + string validParamName = paramName.CheckParamName(); string notNullValue = value.CheckNotZeroLengthOrWhiteSpaceOnly(validParamName); @@ -544,8 +543,8 @@ public static string ValidBase64([NotNull] string? value, [NotNull] string custo [NotNull, CallerArgumentExpression(nameof(value))] string paramName = "") { (string validParamName, string validCustomMessage) = - (paramName.CheckNotZeroLengthOrWhiteSpaceOnly(), - customMessage.CheckNotZeroLengthOrWhiteSpaceOnly()); + (paramName.CheckParamName(), + customMessage.CheckExceptionMessage()); string notNullValue = value.ValueOrThrowIfNullZeroLengthOrWhiteSpaceOnly(validParamName, validCustomMessage); @@ -609,9 +608,9 @@ private static TNullable CompliesWithExpected( { TNullable notNullValue = value.Check(nameof(value)); Func notNullValidator = validator.Check(); - string notNullParamName = paramName.CheckNotZeroLengthOrWhiteSpaceOnly(); + string notNullParamName = paramName.CheckParamName(); string notNullPreconditionDescription - = preconditionDescription.CheckNotZeroLengthOrWhiteSpaceOnly(); + = preconditionDescription.CheckExceptionMessage(); return notNullValidator(notNullValue) != expected ? throw new ArgumentException(paramName: notNullParamName, message: notNullPreconditionDescription) diff --git a/src/Validations/ArgumentsHelpers/Extensions.cs b/src/Validations/ArgumentsHelpers/Extensions.cs index 014e54a..9038bd7 100644 --- a/src/Validations/ArgumentsHelpers/Extensions.cs +++ b/src/Validations/ArgumentsHelpers/Extensions.cs @@ -52,8 +52,7 @@ internal static string CheckNotWhiteSpaceOnly(this string value, string paramNam [return: NotNull] internal static string CheckNotZeroLengthOrWhiteSpaceOnly( - [NotNull] this string? value, - [CallerArgumentExpression(nameof(value))] string paramName = "") + [NotNull] this string? value, string paramName = "") => Check(value, paramName) .CheckNotZeroLength(paramName) .CheckNotWhiteSpaceOnly(paramName); From 683172723211832aca82f743a5de9c0d62377ec6 Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Mon, 9 Jun 2025 22:28:30 -0400 Subject: [PATCH 10/11] Removing build warnings --- src/Validations/Arguments.cs | 2 +- src/Validations/ArgumentsHelpers/Extensions.cs | 4 ++-- src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Validations/Arguments.cs b/src/Validations/Arguments.cs index b24de5e..048631a 100644 --- a/src/Validations/Arguments.cs +++ b/src/Validations/Arguments.cs @@ -606,7 +606,7 @@ private static TNullable CompliesWithExpected( [NotNull] string paramName, bool expected) where TNullable : class { - TNullable notNullValue = value.Check(nameof(value)); + TNullable notNullValue = value.Check(); Func notNullValidator = validator.Check(); string notNullParamName = paramName.CheckParamName(); string notNullPreconditionDescription diff --git a/src/Validations/ArgumentsHelpers/Extensions.cs b/src/Validations/ArgumentsHelpers/Extensions.cs index 9038bd7..1bac13b 100644 --- a/src/Validations/ArgumentsHelpers/Extensions.cs +++ b/src/Validations/ArgumentsHelpers/Extensions.cs @@ -53,7 +53,7 @@ internal static string CheckNotWhiteSpaceOnly(this string value, string paramNam [return: NotNull] internal static string CheckNotZeroLengthOrWhiteSpaceOnly( [NotNull] this string? value, string paramName = "") - => Check(value, paramName) + => CheckWithParamName(value, paramName) .CheckNotZeroLength(paramName) .CheckNotWhiteSpaceOnly(paramName); @@ -94,7 +94,7 @@ internal static TEnumType ValueOrThrowIfNotDefined(this TEnumType val internal static TType[] ValueOrThrowIfNullOrWithLessThanElements( [NotNull] this TType[]? value, int minimumElements, string paramName) { - _ = OutOfRangeChecks.GreaterThanOrEqualTo(Check(value, paramName).Length, minimumElements, paramName); + _ = OutOfRangeChecks.GreaterThanOrEqualTo(CheckWithParamName(value, paramName).Length, minimumElements, paramName); return value!; } diff --git a/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs b/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs index c0f848b..752740d 100644 --- a/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs +++ b/src/Validations/ArgumentsHelpers/OutOfRangeChecks.cs @@ -104,7 +104,7 @@ internal static TComparable Between( string notNullParamName = paramName.CheckParamName(); return range.Contains( - value.Check(notNullParamName), + value.CheckWithParamName(notNullParamName), notNullParamName, customMessage: null!); From 2e3d3c8e3a7cc52646d6aaf92cca7bbbedad434d Mon Sep 17 00:00:00 2001 From: Lorenzo Solano Martinez Date: Mon, 9 Jun 2025 22:51:48 -0400 Subject: [PATCH 11/11] Update package description --- src/Validations/Validations.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Validations/Validations.csproj b/src/Validations/Validations.csproj index 1390452..41c50e4 100644 --- a/src/Validations/Validations.csproj +++ b/src/Validations/Validations.csproj @@ -60,6 +60,7 @@ Improvements - Migrate to .NET 9 - Increase test coverage to 100 percent - Analyze project using sonarcloud.io (see https://sonarcloud.io/project/overview?id=lsolano_triplex) + - Removed all compiler warnings