Switch to new ArgumentNullException extensions in D2D1 projects

このコミットが含まれているのは:
Sergio Pedri committed 2023-02-25 16:24:52 +01:00
1 親 6f7bbff6cf
コミット 7be3d577c4
7ファイル変更
+21 -110

検索条件に一致するファイルはありません

+2 -8
ファイルの表示
@@ -18,10 +18,7 @@ internal static class FixedCountList<T>
/// <param name="index">The initial index within <paramref name="array"/>.</param>
public static void CopyTo(IFixedCountList<T> list, T[] array, int index)
{
if (array is null)
{
ThrowHelper.ThrowArgumentNullException(nameof(array), "The input array cannot be null.");
}
default(ArgumentNullException).ThrowIfNull(array);
Span<T> span = array.AsSpan(index);
@@ -44,10 +41,7 @@ internal static class FixedCountList<T>
/// <param name="index">The initial index within <paramref name="array"/>.</param>
public static void CopyTo(IFixedCountList<T> 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)
{
+1 -1
ファイルの表示
@@ -220,7 +220,7 @@ unsafe partial class PixelShaderEffect<T>
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
@@ -62,10 +62,7 @@ partial class PixelShaderEffect<T>
}
set
{
if (value is null)
{
ThrowHelper.ThrowArgumentNullException(nameof(value), "Input resource texture managers cannot be null.");
}
default(ArgumentNullException).ThrowIfNull(value);
ValidateIndex(index);
-26
ファイルの表示
@@ -20,32 +20,6 @@ internal static class ThrowHelper
throw new ArgumentException(message, name);
}
/// <summary>
/// Throws a new <see cref="ArgumentException"/>.
/// </summary>
/// <typeparam name="T">The type of expected result.</typeparam>
/// <param name="name">The argument name.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
/// <returns>This method always throws, so it actually never returns a value.</returns>
[DoesNotReturn]
public static T ThrowArgumentException<T>(string? name, string? message)
{
throw new ArgumentException(message, name);
}
/// <summary>
/// Throws a new <see cref="ArgumentException"/>.
/// </summary>
/// <param name="name">The argument name.</param>
/// <param name="message">The message to include in the exception.</param>
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
[DoesNotReturn]
public static void ThrowArgumentNullException(string? name, string? message)
{
throw new ArgumentNullException(name, message);
}
/// <summary>
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
/// </summary>
+1 -4
ファイルの表示
@@ -433,10 +433,7 @@ public static class D2D1PixelShader
public static unsafe void SetConstantBufferForD2D1DrawInfo<T>(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);
+12 -54
ファイルの表示
@@ -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<T>(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<T>(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<T>.Instance.Id)
{
@@ -504,10 +493,7 @@ public static unsafe class D2D1PixelShaderEffect
public static void SetConstantBufferForD2D1Effect<T>(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
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1properties-setvalue(uint32_d2d1_property_type_constbyte_uint32)"/>.</remarks>
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
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1properties-setvalue(uint32_d2d1_property_type_constbyte_uint32)"/>.</remarks>
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<ID2D1ResourceTextureManager> resourceTextureManager2 = default;
@@ -581,15 +553,8 @@ public static unsafe class D2D1PixelShaderEffect
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1properties-setvalue(uint32_d2d1_property_type_constbyte_uint32)"/>.</remarks>
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<T>(void* d2D1Effect, D2D1TransformMapper<T> 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<T> object cannot be null.");
}
default(ArgumentNullException).ThrowIfNull(d2D1Effect);
default(ArgumentNullException).ThrowIfNull(transformMapper);
using ComPtr<ID2D1TransformMapper> transformMapper2 = default;
+4 -13
ファイルの表示
@@ -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<T>
/// <returns>The resulting <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.</returns>
public static D2D1TransformMapper<T> Inflate(Accessor<int> accessor)
{
if (accessor is null)
{
ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory<T>.Accessor<int> object cannot be null.");
}
default(ArgumentNullException).ThrowIfNull(accessor);
return new D2D1InflateTransformMapper<T>.DynamicAmount { Accessor = accessor };
}
@@ -56,10 +53,7 @@ public static class D2D1TransformMapperFactory<T>
/// <returns>The resulting <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.</returns>
public static D2D1TransformMapper<T> Inflate(Accessor<(int Left, int Top, int Right, int Bottom)> accessor)
{
if (accessor is null)
{
ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory<T>.Accessor<(int Left, int Top, int Right, int Bottom)> object cannot be null.");
}
default(ArgumentNullException).ThrowIfNull(accessor);
return new D2D1InflateTransformMapper<T>.DynamicLeftTopRightBottomAmount { Accessor = accessor };
}
@@ -81,10 +75,7 @@ public static class D2D1TransformMapperFactory<T>
/// <returns>The resulting <see cref="D2D1TransformMapper{T}"/> instance for an affine transform.</returns>
public static D2D1TransformMapper<T> Transform(Accessor<Matrix3x2> accessor)
{
if (accessor is null)
{
ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory<T>.Accessor<Matrix3x2> object cannot be null.");
}
default(ArgumentNullException).ThrowIfNull(accessor);
return new D2D1AffineTransformMapper<T>.DynamicMatrix { Accessor = accessor };
}