Use ArgumentOutOfRangeException throw helper methods

This commit is contained in:
Berkan Diler 2024-03-05 10:20:30 +01:00
parent 9bac60a98f
commit a891303484
8 changed files with 10 additions and 15 deletions

View File

@ -58,9 +58,9 @@ public override void PostProcess()
private void applyStacking(Beatmap<OsuHitObject> beatmap, int startIndex, int endIndex)
{
if (startIndex > endIndex) throw new ArgumentOutOfRangeException(nameof(startIndex), $"{nameof(startIndex)} cannot be greater than {nameof(endIndex)}.");
if (startIndex < 0) throw new ArgumentOutOfRangeException(nameof(startIndex), $"{nameof(startIndex)} cannot be less than 0.");
if (endIndex < 0) throw new ArgumentOutOfRangeException(nameof(endIndex), $"{nameof(endIndex)} cannot be less than 0.");
ArgumentOutOfRangeException.ThrowIfGreaterThan(startIndex, endIndex);
ArgumentOutOfRangeException.ThrowIfNegative(startIndex);
ArgumentOutOfRangeException.ThrowIfNegative(endIndex);
int extendedEndIndex = endIndex;

View File

@ -334,7 +334,7 @@ private DistanceSnapGrid createDistanceSnapGrid(IEnumerable<HitObject> selectedH
/// <returns>The <see cref="OsuDistanceSnapGrid"/> from a selected <see cref="HitObject"/> to a target <see cref="HitObject"/>.</returns>
private OsuDistanceSnapGrid createGrid(Func<HitObject, bool> sourceSelector, int targetOffset = 1)
{
if (targetOffset < 1) throw new ArgumentOutOfRangeException(nameof(targetOffset));
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(targetOffset);
int sourceIndex = -1;

View File

@ -23,8 +23,7 @@ public class TimeSignature : IEquatable<TimeSignature>
public TimeSignature(int numerator)
{
if (numerator < 1)
throw new ArgumentOutOfRangeException(nameof(numerator), numerator, "The numerator of a time signature must be positive.");
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(numerator);
Numerator = numerator;
}

View File

@ -27,8 +27,7 @@ public class ReverseQueue<T> : IEnumerable<T>
public ReverseQueue(int initialCapacity)
{
if (initialCapacity <= 0)
throw new ArgumentOutOfRangeException(nameof(initialCapacity));
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(initialCapacity);
items = new T[initialCapacity];
capacity = initialCapacity;

View File

@ -40,8 +40,7 @@ public PathType(SplineType splineType)
public static PathType BSpline(int degree)
{
if (degree <= 0)
throw new ArgumentOutOfRangeException(nameof(degree), "The degree of a B-Spline path must be greater than zero.");
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(degree);
return new PathType { Type = SplineType.BSpline, Degree = degree };
}

View File

@ -33,8 +33,7 @@ public partial class SimpleStatisticTable : CompositeDrawable
/// <param name="items">The <see cref="SimpleStatisticItem"/>s to display in this row.</param>
public SimpleStatisticTable(int columnCount, [ItemNotNull] IEnumerable<SimpleStatisticItem> items)
{
if (columnCount < 1)
throw new ArgumentOutOfRangeException(nameof(columnCount));
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(columnCount);
this.columnCount = columnCount;
this.items = items.ToArray();

View File

@ -35,8 +35,7 @@ public class LimitedCapacityQueue<T> : IEnumerable<T>
/// <param name="capacity">The number of items the queue can hold.</param>
public LimitedCapacityQueue(int capacity)
{
if (capacity < 0)
throw new ArgumentOutOfRangeException(nameof(capacity));
ArgumentOutOfRangeException.ThrowIfNegative(capacity);
this.capacity = capacity;
array = new T[capacity];

View File

@ -58,7 +58,7 @@ public static ulong NextULong(int seed, int series = 0)
/// </param>
public static int NextInt(int maxValue, int seed, int series = 0)
{
if (maxValue <= 0) throw new ArgumentOutOfRangeException(nameof(maxValue));
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(maxValue);
return (int)(NextULong(seed, series) % (ulong)maxValue);
}