diff --git a/src/ComputeSharp.D2D1.Uwp/Collections/FixedCountList{T}.cs b/src/ComputeSharp.D2D1.Uwp/Collections/FixedCountList{T}.cs index 1695dd81..cd456511 100644 --- a/src/ComputeSharp.D2D1.Uwp/Collections/FixedCountList{T}.cs +++ b/src/ComputeSharp.D2D1.Uwp/Collections/FixedCountList{T}.cs @@ -18,10 +18,7 @@ internal static class FixedCountList /// The initial index within . public static void CopyTo(IFixedCountList list, T[] array, int index) { - if (array is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(array), "The input array cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(array); Span span = array.AsSpan(index); @@ -44,10 +41,7 @@ internal static class FixedCountList /// The initial index within . public static void CopyTo(IFixedCountList list, Array array, int index) { - if (array is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(array), "The input array cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(array); if ((uint)index >= array.Length) { diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs index 1505c86e..e28378db 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs @@ -220,7 +220,7 @@ unsafe partial class PixelShaderEffect else if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_ALLOW_NULL_EFFECT_INPUTS) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE) { // If the source is null and this is not explicitly allowed, the invocation is not valid - ThrowHelper.ThrowArgumentNullException(nameof(value), "The effect source cannot be null."); + default(ArgumentNullException).Throw(nameof(value)); } // Save the managed wrapper and realized image diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs index 9e3f9c4e..d35ab020 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs @@ -62,10 +62,7 @@ partial class PixelShaderEffect } set { - if (value is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(value), "Input resource texture managers cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(value); ValidateIndex(index); diff --git a/src/ComputeSharp.D2D1/Helpers/ThrowHelper.cs b/src/ComputeSharp.D2D1/Helpers/ThrowHelper.cs index f80e64f4..e164d403 100644 --- a/src/ComputeSharp.D2D1/Helpers/ThrowHelper.cs +++ b/src/ComputeSharp.D2D1/Helpers/ThrowHelper.cs @@ -20,32 +20,6 @@ internal static class ThrowHelper throw new ArgumentException(message, name); } - /// - /// Throws a new . - /// - /// The type of expected result. - /// The argument name. - /// The message to include in the exception. - /// Thrown with the specified parameters. - /// This method always throws, so it actually never returns a value. - [DoesNotReturn] - public static T ThrowArgumentException(string? name, string? message) - { - throw new ArgumentException(message, name); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The message to include in the exception. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowArgumentNullException(string? name, string? message) - { - throw new ArgumentNullException(name, message); - } - /// /// Throws a new . /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index e49184e8..e4b91749 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -433,10 +433,7 @@ public static class D2D1PixelShader public static unsafe void SetConstantBufferForD2D1DrawInfo(void* d2D1DrawInfo, in T shader) where T : unmanaged, ID2D1PixelShader { - if (d2D1DrawInfo is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(d2D1DrawInfo), "The input ID2D1DrawInfo object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(d2D1DrawInfo); D2D1DrawInfoDispatchDataLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo); diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs index 3ce44ca3..d9adec9c 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs @@ -1,7 +1,6 @@ using System; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Extensions; -using ComputeSharp.D2D1.Helpers; using ComputeSharp.D2D1.Interop.Effects; using ComputeSharp.D2D1.Shaders.Interop.Buffers; using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers; @@ -31,10 +30,7 @@ public static unsafe class D2D1PixelShaderEffect public static void RegisterForD2D1Factory1(void* d2D1Factory1, out Guid effectId) where T : unmanaged, ID2D1PixelShader { - if (d2D1Factory1 is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(d2D1Factory1), "The input ID2D1Factory1 object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(d2D1Factory1); effectId = default; @@ -475,15 +471,8 @@ public static unsafe class D2D1PixelShaderEffect public static void CreateFromD2D1DeviceContext(void* d2D1DeviceContext, void** d2D1Effect) where T : unmanaged, ID2D1PixelShader { - if (d2D1DeviceContext is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(d2D1DeviceContext), "The input ID2D1DeviceContext object cannot be null."); - } - - if (d2D1Effect is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The pointer to the target ID2D1Effect result cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(d2D1DeviceContext); + default(ArgumentNullException).ThrowIfNull(d2D1Effect); fixed (Guid* pGuid = &PixelShaderEffect.For.Instance.Id) { @@ -504,10 +493,7 @@ public static unsafe class D2D1PixelShaderEffect public static void SetConstantBufferForD2D1Effect(void* d2D1Effect, in T shader) where T : unmanaged, ID2D1PixelShader { - if (d2D1Effect is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The input ID2D1DeviceContext object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(d2D1Effect); D2D1EffectDispatchDataLoader dataLoader = new((ID2D1Effect*)d2D1Effect); @@ -524,15 +510,8 @@ public static unsafe class D2D1PixelShaderEffect /// For more info, see . public static void SetResourceTextureManagerForD2D1Effect(void* d2D1Effect, void* resourceTextureManager, int resourceTextureIndex) { - if (d2D1Effect is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The input ID2D1Effect object cannot be null."); - } - - if (resourceTextureManager is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(resourceTextureManager), "The input ID2D1ResourceTextureManager object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(d2D1Effect); + default(ArgumentNullException).ThrowIfNull(resourceTextureManager); ((ID2D1Effect*)d2D1Effect)->SetValue( index: D2D1PixelShaderEffectProperty.ResourceTextureManager0 + (uint)resourceTextureIndex, @@ -551,15 +530,8 @@ public static unsafe class D2D1PixelShaderEffect /// For more info, see . public static void SetResourceTextureManagerForD2D1Effect(void* d2D1Effect, D2D1ResourceTextureManager resourceTextureManager, int resourceTextureIndex) { - if (d2D1Effect is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The input ID2D1Effect object cannot be null."); - } - - if (resourceTextureManager is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(resourceTextureManager), "The input D2D1ResourceTextureManager object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(d2D1Effect); + default(ArgumentNullException).ThrowIfNull(resourceTextureManager); using ComPtr resourceTextureManager2 = default; @@ -581,15 +553,8 @@ public static unsafe class D2D1PixelShaderEffect /// For more info, see . public static void SetTransformMapperForD2D1Effect(void* d2D1Effect, void* transformMapper) { - if (d2D1Effect is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The input ID2D1Effect object cannot be null."); - } - - if (transformMapper is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(transformMapper), "The input ID2D1TransformMapper object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(d2D1Effect); + default(ArgumentNullException).ThrowIfNull(transformMapper); ((ID2D1Effect*)d2D1Effect)->SetValue( index: D2D1PixelShaderEffectProperty.TransformMapper, @@ -608,15 +573,8 @@ public static unsafe class D2D1PixelShaderEffect public static void SetTransformMapperForD2D1Effect(void* d2D1Effect, D2D1TransformMapper transformMapper) where T : unmanaged, ID2D1PixelShader { - if (d2D1Effect is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The input ID2D1Effect object cannot be null."); - } - - if (transformMapper is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(transformMapper), "The input D2D1TransformMapper object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(d2D1Effect); + default(ArgumentNullException).ThrowIfNull(transformMapper); using ComPtr transformMapper2 = default; diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs index 3e0d1ff2..1e065117 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs @@ -1,5 +1,5 @@ +using System; using System.Numerics; -using ComputeSharp.D2D1.Helpers; using ComputeSharp.D2D1.Shaders.Interop.Factories; namespace ComputeSharp.D2D1.Interop; @@ -41,10 +41,7 @@ public static class D2D1TransformMapperFactory /// The resulting instance for an inflate transform. public static D2D1TransformMapper Inflate(Accessor accessor) { - if (accessor is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory.Accessor object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(accessor); return new D2D1InflateTransformMapper.DynamicAmount { Accessor = accessor }; } @@ -56,10 +53,7 @@ public static class D2D1TransformMapperFactory /// The resulting instance for an inflate transform. public static D2D1TransformMapper Inflate(Accessor<(int Left, int Top, int Right, int Bottom)> accessor) { - if (accessor is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory.Accessor<(int Left, int Top, int Right, int Bottom)> object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(accessor); return new D2D1InflateTransformMapper.DynamicLeftTopRightBottomAmount { Accessor = accessor }; } @@ -81,10 +75,7 @@ public static class D2D1TransformMapperFactory /// The resulting instance for an affine transform. public static D2D1TransformMapper Transform(Accessor accessor) { - if (accessor is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory.Accessor object cannot be null."); - } + default(ArgumentNullException).ThrowIfNull(accessor); return new D2D1AffineTransformMapper.DynamicMatrix { Accessor = accessor }; }