diff --git a/src/GuardClauses/GuardAgainstOutOfRangeExtensions.cs b/src/GuardClauses/GuardAgainstOutOfRangeExtensions.cs index 6d2cfd5..06da4e2 100644 --- a/src/GuardClauses/GuardAgainstOutOfRangeExtensions.cs +++ b/src/GuardClauses/GuardAgainstOutOfRangeExtensions.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; +using GuardClauses; namespace Ardalis.GuardClauses; @@ -36,31 +37,10 @@ public static string LengthOutOfRange(this IGuardClause guardClause, string? message = null) #endif { - if (maxLength < minLength) - { - throw new ArgumentException( - message ?? - $"Min length must be equal or less than max length.", - parameterName); - } - - Guard.Against.NegativeOrZero(minLength, nameof(minLength)); - if (input.Length < minLength) - { - throw new ArgumentException( - message ?? - $"Input {parameterName} with length {input.Length} is too short. Minimum length is {minLength}.", - parameterName); - } - - 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); - } + Guard.Against.Negative(maxLength - minLength, parameterName: "min or max length", + message: "Min length must be equal or less than max length."); + Guard.Against.StringTooShort(input, minLength, nameof(minLength)); + Guard.Against.StringTooLong(input, maxLength, nameof(maxLength)); return input; }