1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 16:47:46 +08:00

Merge pull request #27501 from turbedi/throw_helper

Use ThrowHelper methods in more places
This commit is contained in:
Bartłomiej Dach 2024-03-07 11:36:21 +01:00 committed by GitHub
commit 3d8fdc52a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 15 additions and 25 deletions

View File

@ -58,9 +58,9 @@ namespace osu.Game.Rulesets.Osu.Beatmaps
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 @@ namespace osu.Game.Rulesets.Osu.Edit
/// <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 @@ namespace osu.Game.Beatmaps.Timing
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

@ -489,8 +489,7 @@ namespace osu.Game.Database
/// <param name="action">The work to run.</param>
public Task WriteAsync(Action<Realm> action)
{
if (isDisposed)
throw new ObjectDisposedException(nameof(RealmAccess));
ObjectDisposedException.ThrowIf(isDisposed, this);
// Required to ensure the write is tracked and accounted for before disposal.
// Can potentially be avoided if we have a need to do so in the future.
@ -675,8 +674,7 @@ namespace osu.Game.Database
private Realm getRealmInstance()
{
if (isDisposed)
throw new ObjectDisposedException(nameof(RealmAccess));
ObjectDisposedException.ThrowIf(isDisposed, this);
bool tookSemaphoreLock = false;
@ -1189,8 +1187,7 @@ namespace osu.Game.Database
if (!ThreadSafety.IsUpdateThread)
throw new InvalidOperationException(@$"{nameof(BlockAllOperations)} must be called from the update thread.");
if (isDisposed)
throw new ObjectDisposedException(nameof(RealmAccess));
ObjectDisposedException.ThrowIf(isDisposed, this);
SynchronizationContext? syncContext = null;

View File

@ -80,8 +80,7 @@ namespace osu.Game.IO
public override Storage GetStorageForDirectory(string path)
{
if (string.IsNullOrEmpty(path))
throw new ArgumentException("Must be non-null and not empty string", nameof(path));
ArgumentException.ThrowIfNullOrEmpty(path);
if (!path.EndsWith(Path.DirectorySeparatorChar))
path += Path.DirectorySeparatorChar;

View File

@ -27,8 +27,7 @@ namespace osu.Game.Rulesets.Difficulty.Utils
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 @@ namespace osu.Game.Rulesets.Objects.Types
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

@ -135,8 +135,7 @@ namespace osu.Game.Rulesets.UI
protected DrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null)
: base(ruleset)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap), "Beatmap cannot be null.");
ArgumentNullException.ThrowIfNull(beatmap);
if (!(beatmap is Beatmap<TObject> tBeatmap))
throw new ArgumentException($"{GetType()} expected the beatmap to contain hitobjects of type {typeof(TObject)}.", nameof(beatmap));

View File

@ -33,8 +33,7 @@ namespace osu.Game.Screens.Ranking.Statistics
/// <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 @@ namespace osu.Game.Utils
/// <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 @@ namespace osu.Game.Utils
/// </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);
}