Browse Source

[SL.Core] Make Guard.NotNull() and DebugGuard.NotNull() generic

pull/1087/head
Anton Firszov 8 years ago
parent
commit
a5bfedd97c
  1. 4
      src/SixLabors.Core/Helpers/DebugGuard.cs
  2. 4
      src/SixLabors.Core/Helpers/Guard.cs
  3. 2
      src/SixLabors.Core/SixLabors.Core.csproj.DotSettings
  4. 2
      tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs
  5. 4
      tests/SixLabors.Core.Tests/Helpers/GuardTests.cs

4
src/SixLabors.Core/Helpers/DebugGuard.cs

@ -19,8 +19,10 @@ namespace SixLabors
/// <param name="target">The target object, which cannot be null.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null</exception>
/// <typeparam name="T">The type of the object to verify</typeparam>
[Conditional("DEBUG")]
public static void NotNull(object target, string parameterName)
public static void NotNull<T>(T target, string parameterName)
where T : class
{
if (target == null)
{

4
src/SixLabors.Core/Helpers/Guard.cs

@ -22,7 +22,9 @@ namespace SixLabors
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <param name="message">The error message, if any to add to the exception.</param>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null</exception>
public static void NotNull(object target, string parameterName, string message = "")
/// <typeparam name="T">The type of the object to verify</typeparam>
public static void NotNull<T>(T target, string parameterName, string message = "")
where T : class
{
if (target == null)
{

2
src/SixLabors.Core/SixLabors.Core.csproj.DotSettings

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helpers/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

2
tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs

@ -39,7 +39,7 @@ namespace SixLabors.Helpers.Tests
{
Assert.Throws<ArgumentNullException>(() =>
{
DebugGuard.NotNull(null, "myParamName");
DebugGuard.NotNull((object)null, "myParamName");
});
}

4
tests/SixLabors.Core.Tests/Helpers/GuardTests.cs

@ -21,7 +21,7 @@ namespace SixLabors.Helpers.Tests
{
Assert.Throws<ArgumentNullException>(() =>
{
Guard.NotNull(null, "myParamName");
Guard.NotNull((object)null, "myParamName");
});
}
@ -30,7 +30,7 @@ namespace SixLabors.Helpers.Tests
{
var exception = Assert.Throws<ArgumentNullException>(() =>
{
Guard.NotNull(null, "myParamName", "myTestMessage");
Guard.NotNull((object)null, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);

Loading…
Cancel
Save