diff --git a/src/SixLabors.Core/Helpers/DebugGuard.cs b/src/SixLabors.Core/Helpers/DebugGuard.cs index c649372ee..f41d7eacf 100644 --- a/src/SixLabors.Core/Helpers/DebugGuard.cs +++ b/src/SixLabors.Core/Helpers/DebugGuard.cs @@ -19,8 +19,10 @@ namespace SixLabors /// The target object, which cannot be null. /// The name of the parameter that is to be checked. /// is null + /// The type of the object to verify [Conditional("DEBUG")] - public static void NotNull(object target, string parameterName) + public static void NotNull(T target, string parameterName) + where T : class { if (target == null) { diff --git a/src/SixLabors.Core/Helpers/Guard.cs b/src/SixLabors.Core/Helpers/Guard.cs index 3a38551d8..41db42fc1 100644 --- a/src/SixLabors.Core/Helpers/Guard.cs +++ b/src/SixLabors.Core/Helpers/Guard.cs @@ -22,7 +22,9 @@ namespace SixLabors /// 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 target, string parameterName, string message = "") + /// The type of the object to verify + public static void NotNull(T target, string parameterName, string message = "") + where T : class { if (target == null) { diff --git a/src/SixLabors.Core/SixLabors.Core.csproj.DotSettings b/src/SixLabors.Core/SixLabors.Core.csproj.DotSettings new file mode 100644 index 000000000..8b01856ae --- /dev/null +++ b/src/SixLabors.Core/SixLabors.Core.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs index 99661dfe0..843b74ded 100644 --- a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs @@ -39,7 +39,7 @@ namespace SixLabors.Helpers.Tests { Assert.Throws(() => { - DebugGuard.NotNull(null, "myParamName"); + DebugGuard.NotNull((object)null, "myParamName"); }); } diff --git a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs index 95901c774..ed2e0b5c7 100644 --- a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs @@ -21,7 +21,7 @@ namespace SixLabors.Helpers.Tests { Assert.Throws(() => { - Guard.NotNull(null, "myParamName"); + Guard.NotNull((object)null, "myParamName"); }); } @@ -30,7 +30,7 @@ namespace SixLabors.Helpers.Tests { var exception = Assert.Throws(() => { - Guard.NotNull(null, "myParamName", "myTestMessage"); + Guard.NotNull((object)null, "myParamName", "myTestMessage"); }); Assert.Equal("myParamName", exception.ParamName);