diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index 603cf566f5..9258beb368 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; namespace SixLabors.ImageSharp { @@ -19,17 +18,11 @@ namespace SixLabors.ImageSharp /// /// The target object, which cannot be null. /// The name of the parameter that is to be checked. - /// The error message, if any to add to the exception. /// is null - public static void NotNull(object value, string parameterName, string message = "") + public static void NotNull(object value, string parameterName) { if (value == null) { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentNullException(parameterName, message); - } - throw new ArgumentNullException(parameterName); } } @@ -60,17 +53,16 @@ namespace SixLabors.ImageSharp /// The type of objects in the /// The target enumeration, which should be checked against being null or empty. /// Name of the parameter. - /// The error message, if any to add to the exception. /// is null. /// is empty. - public static void NotNullOrEmpty(IEnumerable value, string parameterName) + public static void NotNullOrEmpty(ICollection value, string parameterName) { if (value == null) { throw new ArgumentNullException(parameterName); } - if (!value.Any()) + if (value.Count == 0) { throw new ArgumentException("Must not be empty.", parameterName); } @@ -182,15 +174,9 @@ namespace SixLabors.ImageSharp /// Verifies, that the method parameter with specified target value is true /// and throws an exception if it is found to be so. /// - /// - /// The target value, which cannot be false. - /// - /// - /// The name of the parameter that is to be checked. - /// - /// - /// The error message, if any to add to the exception. - /// + /// The target value, which cannot be false. + /// The name of the parameter that is to be checked. + /// The error message, if any to add to the exception. /// /// is false /// diff --git a/src/ImageSharp/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs index 2cdb71fc0e..75d947469b 100644 --- a/src/ImageSharp/ImageExtensions.cs +++ b/src/ImageSharp/ImageExtensions.cs @@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp public static void Save(this Image source, string filePath) where TPixel : struct, IPixel { - Guard.NotNullOrEmpty(filePath, nameof(filePath)); + Guard.NotNullOrWhiteSpace(filePath, nameof(filePath)); string ext = Path.GetExtension(filePath).Trim('.'); IImageFormat format = source.GetConfiguration().ImageFormatsManager.FindFormatByFileExtension(ext); diff --git a/tests/ImageSharp.Tests/Helpers/GuardTests.cs b/tests/ImageSharp.Tests/Helpers/GuardTests.cs index 83075dc83e..42913e02d4 100644 --- a/tests/ImageSharp.Tests/Helpers/GuardTests.cs +++ b/tests/ImageSharp.Tests/Helpers/GuardTests.cs @@ -35,27 +35,27 @@ namespace SixLabors.ImageSharp.Tests.Helpers /// [Fact] [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1122:UseStringEmptyForEmptyStrings", Justification = "Reviewed. Suppression is OK here.")] - public void NotEmptyThrowsWhenEmpty() + public void NotEmptyOrWhiteSpaceThrowsWhenEmpty() { - Assert.Throws(() => Guard.NotNullOrEmpty("", string.Empty)); + Assert.Throws(() => Guard.NotNullOrWhiteSpace("", string.Empty)); } /// /// Tests that the method throws when the argument is whitespace. /// [Fact] - public void NotEmptyThrowsWhenWhitespace() + public void NotEmptyOrWhiteSpaceThrowsOnWhitespace() { - Assert.Throws(() => Guard.NotNullOrEmpty(" ", string.Empty)); + Assert.Throws(() => Guard.NotNullOrWhiteSpace(" ", string.Empty)); } /// /// Tests that the method throws when the argument name is null. /// [Fact] - public void NotEmptyThrowsWhenParameterNameNull() + public void NotEmptyOrWhiteSpaceThrowsWhenParameterNameNull() { - Assert.Throws(() => Guard.NotNullOrEmpty(null, null)); + Assert.Throws(() => Guard.NotNullOrWhiteSpace(null, null)); } ///