Add and use ArgumentOutOfRangeException.ThrowIfLessThan

このコミットが含まれているのは:
Sergio Pedri committed 2023-02-25 17:07:21 +01:00
1 親 b00fc5d9d4
コミット 7a5daf0a61
4ファイル変更
+36 -9

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

+30
ファイルの表示
@@ -53,6 +53,36 @@ internal static class ArgumentOutOfRangeExceptionExtensions
}
}
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is less than <paramref name="other"/>.
/// </summary>
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
/// <param name="value">The argument to validate as less or equal than <paramref name="other"/>.</param>
/// <param name="other">The value to compare with <paramref name="value"/>.</param>
/// <param name="parameterName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
public static void ThrowIfLessThan(this ArgumentOutOfRangeException? _, int value, int other, [CallerArgumentExpression(nameof(value))] string? parameterName = null)
{
if (value < other)
{
Throw(parameterName, value);
}
}
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is less than <paramref name="other"/>.
/// </summary>
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
/// <param name="value">The argument to validate as less or equal than <paramref name="other"/>.</param>
/// <param name="other">The value to compare with <paramref name="value"/>.</param>
/// <param name="parameterName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
public static void ThrowIfLessThan(this ArgumentOutOfRangeException? _, long value, long other, [CallerArgumentExpression(nameof(value))] string? parameterName = null)
{
if (value < other)
{
Throw(parameterName, value);
}
}
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is not in the specified range.
/// </summary>
+2 -3
ファイルの表示
@@ -1,6 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using CommunityToolkit.Diagnostics;
using ComputeSharp.__Internals;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Commands;
@@ -168,7 +167,7 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
default(ArgumentOutOfRangeException).ThrowIfNotInRange(sourceOffsetX, 0, Width);
default(ArgumentOutOfRangeException).ThrowIfNotBetweenOrEqual(width, 1, Width);
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(sourceOffsetX + width, Width, nameof(sourceOffsetX));
Guard.IsGreaterThanOrEqualTo(size, width);
default(ArgumentOutOfRangeException).ThrowIfLessThan(size, width);
using ReferenceTracker.Lease _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using ReferenceTracker.Lease _1 = GetReferenceTracker().GetLease();
@@ -366,7 +365,7 @@ public abstract unsafe partial class Texture1D<T> : IReferenceTrackedObject, IGr
default(ArgumentOutOfRangeException).ThrowIfNotInRange(destinationOffsetX, 0, Width);
default(ArgumentOutOfRangeException).ThrowIfNotBetweenOrEqual(width, 1, Width);
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(destinationOffsetX + width, Width, nameof(destinationOffsetX));
Guard.IsGreaterThanOrEqualTo(size, width);
default(ArgumentOutOfRangeException).ThrowIfLessThan(size, width);
using ReferenceTracker.Lease _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using ReferenceTracker.Lease _1 = GetReferenceTracker().GetLease();
+2 -3
ファイルの表示
@@ -1,6 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using CommunityToolkit.Diagnostics;
using ComputeSharp.__Internals;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Commands;
@@ -183,7 +182,7 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
default(ArgumentOutOfRangeException).ThrowIfNotBetweenOrEqual(height, 1, Height);
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(sourceOffsetX + width, Width, nameof(sourceOffsetX));
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(sourceOffsetY + height, Height, nameof(sourceOffsetY));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height);
default(ArgumentOutOfRangeException).ThrowIfLessThan(size, (long)width * height);
using ReferenceTracker.Lease _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using ReferenceTracker.Lease _1 = GetReferenceTracker().GetLease();
@@ -406,7 +405,7 @@ public abstract unsafe partial class Texture2D<T> : IReferenceTrackedObject, IGr
default(ArgumentOutOfRangeException).ThrowIfNotBetweenOrEqual(height, 1, Height);
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(destinationOffsetX + width, Width, nameof(destinationOffsetX));
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(destinationOffsetY + height, Height, nameof(destinationOffsetY));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height);
default(ArgumentOutOfRangeException).ThrowIfLessThan(size, (long)width * height);
using ReferenceTracker.Lease _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using ReferenceTracker.Lease _1 = GetReferenceTracker().GetLease();
+2 -3
ファイルの表示
@@ -1,6 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using CommunityToolkit.Diagnostics;
using ComputeSharp.__Internals;
using ComputeSharp.Exceptions;
using ComputeSharp.Graphics.Commands;
@@ -198,7 +197,7 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(sourceOffsetX + width, Width, nameof(sourceOffsetX));
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(sourceOffsetY + height, Height, nameof(sourceOffsetY));
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(sourceOffsetZ + depth, Depth, nameof(sourceOffsetZ));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth);
default(ArgumentOutOfRangeException).ThrowIfLessThan(size, (long)width * height * depth);
using ReferenceTracker.Lease _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using ReferenceTracker.Lease _1 = GetReferenceTracker().GetLease();
@@ -447,7 +446,7 @@ public abstract unsafe partial class Texture3D<T> : IReferenceTrackedObject, IGr
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(destinationOffsetX + width, Width, nameof(destinationOffsetX));
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(destinationOffsetY + height, Height, nameof(destinationOffsetY));
default(ArgumentOutOfRangeException).ThrowIfGreaterThan(destinationOffsetZ + depth, Depth, nameof(destinationOffsetZ));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height * depth);
default(ArgumentOutOfRangeException).ThrowIfLessThan(size, (long)width * height * depth);
using ReferenceTracker.Lease _0 = GraphicsDevice.GetReferenceTracker().GetLease();
using ReferenceTracker.Lease _1 = GetReferenceTracker().GetLease();