diff --git a/src/SixLabors.Core/Helpers/Guard.cs b/src/SixLabors.Core/Helpers/Guard.cs
index 41db42fc1a..069c4eb051 100644
--- a/src/SixLabors.Core/Helpers/Guard.cs
+++ b/src/SixLabors.Core/Helpers/Guard.cs
@@ -20,19 +20,13 @@ namespace SixLabors
///
/// 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
/// The type of the object to verify
- public static void NotNull(T target, string parameterName, string message = "")
+ public static void NotNull(T target, string parameterName)
where T : class
{
- if (target == null)
+ if (target is null)
{
- if (!string.IsNullOrWhiteSpace(message))
- {
- throw new ArgumentNullException(parameterName, message);
- }
-
throw new ArgumentNullException(parameterName);
}
}
@@ -44,20 +38,14 @@ namespace SixLabors
///
/// The target string, 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 or contains only blanks.
- public static void NotNullOrEmpty(string target, string parameterName, string message = "")
+ public static void NotNullOrEmpty(string target, string parameterName)
{
- NotNull(target, parameterName, message);
+ NotNull(target, parameterName);
if (string.IsNullOrWhiteSpace(target))
{
- if (!string.IsNullOrWhiteSpace(message))
- {
- throw new ArgumentException(message, parameterName);
- }
-
throw new ArgumentException("Value cannot be null, empty, or cannot contain only whitespace.", parameterName);
}
}
@@ -68,20 +56,14 @@ namespace SixLabors
/// 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 target, string parameterName, string message = "")
+ public static void NotNullOrEmpty(IEnumerable target, string parameterName)
{
- NotNull(target, parameterName, message);
+ NotNull(target, parameterName);
if (!target.Any())
{
- if (!string.IsNullOrWhiteSpace(message))
- {
- throw new ArgumentException(message, parameterName);
- }
-
throw new ArgumentException("Value cannot be empty.", parameterName);
}
}
@@ -247,4 +229,4 @@ namespace SixLabors
}
}
}
-}
+}
\ No newline at end of file
diff --git a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs
index ed2e0b5c75..b3f1b96a0e 100644
--- a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs
+++ b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs
@@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using Xunit;
namespace SixLabors.Helpers.Tests
@@ -25,18 +24,6 @@ namespace SixLabors.Helpers.Tests
});
}
- [Fact]
- public void NotNull_TargetNullWithMessage_ThrowsException()
- {
- var exception = Assert.Throws(() =>
- {
- Guard.NotNull((object)null, "myParamName", "myTestMessage");
- });
-
- Assert.Equal("myParamName", exception.ParamName);
- Assert.True(exception.Message.Contains("myTestMessage"));
- }
-
[Fact]
public void NotNullOrEmpty_TargetNotNullOrEmpty_ThrowsNoException()
{
@@ -73,18 +60,6 @@ namespace SixLabors.Helpers.Tests
Assert.True(exception.Message.Contains("Value cannot be null, empty, or cannot contain only whitespace."));
}
- [Fact]
- public void NotNullOrEmpty_TargetEmptyWithMessage_ThrowsException()
- {
- var exception = Assert.Throws(() =>
- {
- Guard.NotNullOrEmpty(string.Empty, "myParamName", "myTestMessage");
- });
-
- Assert.Equal("myParamName", exception.ParamName);
- Assert.True(exception.Message.Contains("myTestMessage"));
- }
-
[Fact]
public void NotNullOrEmptyIEnumerable_TargetNotNullOrEmpty_ThrowsNoException()
{
@@ -112,18 +87,6 @@ namespace SixLabors.Helpers.Tests
Assert.True(exception.Message.Contains("Value cannot be empty."));
}
- [Fact]
- public void NotNullOrEmptyIEnumerable_TargetEmptyWithMessage_ThrowsException()
- {
- var exception = Assert.Throws(() =>
- {
- Guard.NotNullOrEmpty(new string[] { }, "myParamName", "myTestMessage");
- });
-
- Assert.Equal("myParamName", exception.ParamName);
- Assert.True(exception.Message.Contains("myTestMessage"));
- }
-
[Fact]
public void MustBeLessThan_IsLess_ThrowsNoException()
{