Browse Source

Merge branch 'master' into js/faster-gif

pull/637/head
James Jackson-South 8 years ago
parent
commit
72acc7dd64
  1. 9
      src/ImageSharp/Common/Helpers/DebugGuard.cs
  2. 3
      src/ImageSharp/Common/Helpers/Guard.cs
  3. 1
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs
  4. 8
      tests/ImageSharp.Tests/Helpers/GuardTests.cs

9
src/ImageSharp/Common/Helpers/DebugGuard.cs

@ -17,13 +17,14 @@ namespace SixLabors.ImageSharp
/// Verifies, that the method parameter with specified object value is not null
/// and throws an exception if it is found to be so.
/// </summary>
/// <param name="target">The target object, which cannot be null.</param>
/// <param name="value">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>
/// <exception cref="ArgumentNullException"><paramref name="value"/> is null</exception>
[Conditional("DEBUG")]
public static void NotNull(object target, string parameterName)
public static void NotNull<T>(T value, string parameterName)
where T : class
{
if (target == null)
if (value == null)
{
throw new ArgumentNullException(parameterName);
}

3
src/ImageSharp/Common/Helpers/Guard.cs

@ -19,7 +19,8 @@ namespace SixLabors.ImageSharp
/// <param name="value">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="value"/> is null</exception>
public static void NotNull(object value, string parameterName)
public static void NotNull<T>(T value, string parameterName)
where T : class
{
if (value == null)
{

1
src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs

@ -47,7 +47,6 @@ namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
/// <param name="divisor">The divisor.</param>
internal ErrorDiffuserBase(DenseMatrix<float> matrix, byte divisor)
{
Guard.NotNull(matrix, nameof(matrix));
Guard.MustBeGreaterThan(divisor, 0, nameof(divisor));
this.matrix = matrix;

8
tests/ImageSharp.Tests/Helpers/GuardTests.cs

@ -12,13 +12,17 @@ namespace SixLabors.ImageSharp.Tests.Helpers
/// </summary>
public class GuardTests
{
class Test
{
}
/// <summary>
/// Tests that the <see cref="M:Guard.NotNull"/> method throws when the argument is null.
/// </summary>
[Fact]
public void NotNullThrowsWhenArgIsNull()
{
Assert.Throws<ArgumentNullException>(() => Guard.NotNull(null, "foo"));
Assert.Throws<ArgumentNullException>(() => Guard.NotNull((Test)null, "foo"));
}
/// <summary>
@ -27,7 +31,7 @@ namespace SixLabors.ImageSharp.Tests.Helpers
[Fact]
public void NotNullThrowsWhenArgNameEmpty()
{
Assert.Throws<ArgumentNullException>(() => Guard.NotNull(null, string.Empty));
Assert.Throws<ArgumentNullException>(() => Guard.NotNull((Test)null, string.Empty));
}
/// <summary>

Loading…
Cancel
Save