1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-08 03:12:57 +08:00

Use new ArgumentNullException.ThrowIfNull throw-helper API

This commit is contained in:
Berkan Diler 2022-12-22 21:27:59 +01:00
parent 867a1963be
commit 08d2fbeb8e
27 changed files with 36 additions and 54 deletions

View File

@ -35,8 +35,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy
protected PatternGenerator(LegacyRandom random, HitObject hitObject, ManiaBeatmap beatmap, Pattern previousPattern, IBeatmap originalBeatmap) protected PatternGenerator(LegacyRandom random, HitObject hitObject, ManiaBeatmap beatmap, Pattern previousPattern, IBeatmap originalBeatmap)
: base(hitObject, beatmap, previousPattern) : base(hitObject, beatmap, previousPattern)
{ {
if (random == null) throw new ArgumentNullException(nameof(random)); ArgumentNullException.ThrowIfNull(random);
if (originalBeatmap == null) throw new ArgumentNullException(nameof(originalBeatmap)); ArgumentNullException.ThrowIfNull(originalBeatmap);
Random = random; Random = random;
OriginalBeatmap = originalBeatmap; OriginalBeatmap = originalBeatmap;

View File

@ -33,9 +33,9 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns
protected PatternGenerator(HitObject hitObject, ManiaBeatmap beatmap, Pattern previousPattern) protected PatternGenerator(HitObject hitObject, ManiaBeatmap beatmap, Pattern previousPattern)
{ {
if (hitObject == null) throw new ArgumentNullException(nameof(hitObject)); ArgumentNullException.ThrowIfNull(hitObject);
if (beatmap == null) throw new ArgumentNullException(nameof(beatmap)); ArgumentNullException.ThrowIfNull(beatmap);
if (previousPattern == null) throw new ArgumentNullException(nameof(previousPattern)); ArgumentNullException.ThrowIfNull(previousPattern);
HitObject = hitObject; HitObject = hitObject;
Beatmap = beatmap; Beatmap = beatmap;

View File

@ -22,8 +22,7 @@ namespace osu.Game.Rulesets.Mania.MathUtils
public static void Sort(T[] keys, IComparer<T> comparer) public static void Sort(T[] keys, IComparer<T> comparer)
{ {
if (keys == null) ArgumentNullException.ThrowIfNull(keys);
throw new ArgumentNullException(nameof(keys));
if (keys.Length == 0) if (keys.Length == 0)
return; return;

View File

@ -29,8 +29,7 @@ namespace osu.Game.Rulesets.Mania.UI
public ManiaPlayfield(List<StageDefinition> stageDefinitions) public ManiaPlayfield(List<StageDefinition> stageDefinitions)
{ {
if (stageDefinitions == null) ArgumentNullException.ThrowIfNull(stageDefinitions);
throw new ArgumentNullException(nameof(stageDefinitions));
if (stageDefinitions.Count <= 0) if (stageDefinitions.Count <= 0)
throw new ArgumentException("Can't have zero or fewer stages."); throw new ArgumentException("Can't have zero or fewer stages.");

View File

@ -84,8 +84,8 @@ namespace osu.Game.Rulesets.Osu.Replays
{ {
public int Compare(ReplayFrame? f1, ReplayFrame? f2) public int Compare(ReplayFrame? f1, ReplayFrame? f2)
{ {
if (f1 == null) throw new ArgumentNullException(nameof(f1)); ArgumentNullException.ThrowIfNull(f1);
if (f2 == null) throw new ArgumentNullException(nameof(f2)); ArgumentNullException.ThrowIfNull(f2);
return f1.Time.CompareTo(f2.Time); return f1.Time.CompareTo(f2.Time);
} }

View File

@ -32,7 +32,7 @@ namespace osu.Game.Tournament.Components
public TournamentBeatmapPanel(TournamentBeatmap beatmap, string mod = null) public TournamentBeatmapPanel(TournamentBeatmap beatmap, string mod = null)
{ {
if (beatmap == null) throw new ArgumentNullException(nameof(beatmap)); ArgumentNullException.ThrowIfNull(beatmap);
Beatmap = beatmap; Beatmap = beatmap;
this.mod = mod; this.mod = mod;

View File

@ -211,8 +211,7 @@ namespace osu.Game.Beatmaps.ControlPoints
public static T BinarySearch<T>(IReadOnlyList<T> list, double time) public static T BinarySearch<T>(IReadOnlyList<T> list, double time)
where T : class, IControlPoint where T : class, IControlPoint
{ {
if (list == null) ArgumentNullException.ThrowIfNull(list);
throw new ArgumentNullException(nameof(list));
if (list.Count == 0) if (list.Count == 0)
return null; return null;

View File

@ -15,8 +15,7 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapBackgroundSprite(IWorkingBeatmap working) public BeatmapBackgroundSprite(IWorkingBeatmap working)
{ {
if (working == null) ArgumentNullException.ThrowIfNull(working);
throw new ArgumentNullException(nameof(working));
this.working = working; this.working = working;
} }

View File

@ -18,8 +18,7 @@ namespace osu.Game.Beatmaps.Drawables
public OnlineBeatmapSetCover(IBeatmapSetOnlineInfo set, BeatmapSetCoverType type = BeatmapSetCoverType.Cover) public OnlineBeatmapSetCover(IBeatmapSetOnlineInfo set, BeatmapSetCoverType type = BeatmapSetCoverType.Cover)
{ {
if (set == null) ArgumentNullException.ThrowIfNull(set);
throw new ArgumentNullException(nameof(set));
this.set = set; this.set = set;
this.type = type; this.type = type;

View File

@ -57,8 +57,7 @@ namespace osu.Game.Beatmaps.Formats
public static Decoder<T> GetDecoder<T>(LineBufferedReader stream) public static Decoder<T> GetDecoder<T>(LineBufferedReader stream)
where T : new() where T : new()
{ {
if (stream == null) ArgumentNullException.ThrowIfNull(stream);
throw new ArgumentNullException(nameof(stream));
if (!decoders.TryGetValue(typeof(T), out var typedDecoders)) if (!decoders.TryGetValue(typeof(T), out var typedDecoders))
throw new IOException(@"Unknown decoder type"); throw new IOException(@"Unknown decoder type");

View File

@ -36,8 +36,7 @@ namespace osu.Game.Graphics.Containers
/// <param name="easing">The easing type of the initial transform.</param> /// <param name="easing">The easing type of the initial transform.</param>
public void StartTracking(OsuLogo logo, double duration = 0, Easing easing = Easing.None) public void StartTracking(OsuLogo logo, double duration = 0, Easing easing = Easing.None)
{ {
if (logo == null) ArgumentNullException.ThrowIfNull(logo);
throw new ArgumentNullException(nameof(logo));
if (logo.IsTracking && Logo == null) if (logo.IsTracking && Logo == null)
throw new InvalidOperationException($"Cannot track an instance of {typeof(OsuLogo)} to multiple {typeof(LogoTrackingContainer)}s"); throw new InvalidOperationException($"Cannot track an instance of {typeof(OsuLogo)} to multiple {typeof(LogoTrackingContainer)}s");

View File

@ -114,8 +114,7 @@ namespace osu.Game.Graphics.UserInterface
get => current; get => current;
set set
{ {
if (value == null) ArgumentNullException.ThrowIfNull(value);
throw new ArgumentNullException(nameof(value));
current.UnbindBindings(); current.UnbindBindings();
current.BindTo(value); current.BindTo(value);

View File

@ -23,8 +23,7 @@ namespace osu.Game.IO.FileAbstraction
public void CloseStream(Stream stream) public void CloseStream(Stream stream)
{ {
if (stream == null) ArgumentNullException.ThrowIfNull(stream);
throw new ArgumentNullException(nameof(stream));
stream.Close(); stream.Close();
} }

View File

@ -118,8 +118,7 @@ namespace osu.Game.Online.Chat
/// <param name="name"></param> /// <param name="name"></param>
public void OpenChannel(string name) public void OpenChannel(string name)
{ {
if (name == null) ArgumentNullException.ThrowIfNull(name);
throw new ArgumentNullException(nameof(name));
CurrentChannel.Value = AvailableChannels.FirstOrDefault(c => c.Name == name) ?? throw new ChannelNotFoundException(name); CurrentChannel.Value = AvailableChannels.FirstOrDefault(c => c.Name == name) ?? throw new ChannelNotFoundException(name);
} }
@ -130,8 +129,7 @@ namespace osu.Game.Online.Chat
/// <param name="user">The user the private channel is opened with.</param> /// <param name="user">The user the private channel is opened with.</param>
public void OpenPrivateChannel(APIUser user) public void OpenPrivateChannel(APIUser user)
{ {
if (user == null) ArgumentNullException.ThrowIfNull(user);
throw new ArgumentNullException(nameof(user));
if (user.Id == api.LocalUser.Value.Id) if (user.Id == api.LocalUser.Value.Id)
return; return;

View File

@ -70,7 +70,7 @@ namespace osu.Game.Overlays
/// <see cref="APIChangelogBuild.DisplayVersion"/> are specified, the header will instantly display them.</param> /// <see cref="APIChangelogBuild.DisplayVersion"/> are specified, the header will instantly display them.</param>
public void ShowBuild([NotNull] APIChangelogBuild build) public void ShowBuild([NotNull] APIChangelogBuild build)
{ {
if (build == null) throw new ArgumentNullException(nameof(build)); ArgumentNullException.ThrowIfNull(build);
Current.Value = build; Current.Value = build;
Show(); Show();
@ -78,8 +78,8 @@ namespace osu.Game.Overlays
public void ShowBuild([NotNull] string updateStream, [NotNull] string version) public void ShowBuild([NotNull] string updateStream, [NotNull] string version)
{ {
if (updateStream == null) throw new ArgumentNullException(nameof(updateStream)); ArgumentNullException.ThrowIfNull(updateStream);
if (version == null) throw new ArgumentNullException(nameof(version)); ArgumentNullException.ThrowIfNull(version);
performAfterFetch(() => performAfterFetch(() =>
{ {

View File

@ -58,7 +58,7 @@ namespace osu.Game.Overlays
/// <exception cref="InvalidOperationException">If <paramref name="configManager"/> is already being tracked from the same <paramref name="source"/>.</exception> /// <exception cref="InvalidOperationException">If <paramref name="configManager"/> is already being tracked from the same <paramref name="source"/>.</exception>
public void BeginTracking(object source, ITrackableConfigManager configManager) public void BeginTracking(object source, ITrackableConfigManager configManager)
{ {
if (configManager == null) throw new ArgumentNullException(nameof(configManager)); ArgumentNullException.ThrowIfNull(configManager);
if (trackedConfigManagers.ContainsKey((source, configManager))) if (trackedConfigManagers.ContainsKey((source, configManager)))
throw new InvalidOperationException($"{nameof(configManager)} is already registered."); throw new InvalidOperationException($"{nameof(configManager)} is already registered.");
@ -82,7 +82,7 @@ namespace osu.Game.Overlays
/// <exception cref="InvalidOperationException">If <paramref name="configManager"/> is not being tracked from the same <paramref name="source"/>.</exception> /// <exception cref="InvalidOperationException">If <paramref name="configManager"/> is not being tracked from the same <paramref name="source"/>.</exception>
public void StopTracking(object source, ITrackableConfigManager configManager) public void StopTracking(object source, ITrackableConfigManager configManager)
{ {
if (configManager == null) throw new ArgumentNullException(nameof(configManager)); ArgumentNullException.ThrowIfNull(configManager);
if (!trackedConfigManagers.TryGetValue((source, configManager), out var existing)) if (!trackedConfigManagers.TryGetValue((source, configManager), out var existing))
return; return;

View File

@ -28,8 +28,7 @@ namespace osu.Game.Overlays.Volume
get => current; get => current;
set set
{ {
if (value == null) ArgumentNullException.ThrowIfNull(value);
throw new ArgumentNullException(nameof(value));
current.UnbindBindings(); current.UnbindBindings();
current.BindTo(value); current.BindTo(value);

View File

@ -126,8 +126,7 @@ namespace osu.Game.Rulesets.Mods
get => this; get => this;
set set
{ {
if (value == null) ArgumentNullException.ThrowIfNull(value);
throw new ArgumentNullException(nameof(value));
if (currentBound != null) UnbindFrom(currentBound); if (currentBound != null) UnbindFrom(currentBound);
BindTo(currentBound = value); BindTo(currentBound = value);

View File

@ -208,8 +208,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary> /// </summary>
public void Apply([NotNull] HitObject hitObject) public void Apply([NotNull] HitObject hitObject)
{ {
if (hitObject == null) ArgumentNullException.ThrowIfNull(hitObject);
throw new ArgumentNullException($"Cannot apply a null {nameof(HitObject)}.");
Apply(new SyntheticHitObjectEntry(hitObject)); Apply(new SyntheticHitObjectEntry(hitObject));
} }

View File

@ -14,7 +14,7 @@ namespace osu.Game.Rulesets.UI
{ {
public override void Add(T judgement) public override void Add(T judgement)
{ {
if (judgement == null) throw new ArgumentNullException(nameof(judgement)); ArgumentNullException.ThrowIfNull(judgement);
// remove any existing judgements for the judged object. // remove any existing judgements for the judged object.
// this can be the case when rewinding. // this can be the case when rewinding.

View File

@ -71,8 +71,8 @@ namespace osu.Game.Scoring
// These properties are known to be non-null, but these final checks ensure a null hasn't come from somewhere (or the refetch has failed). // These properties are known to be non-null, but these final checks ensure a null hasn't come from somewhere (or the refetch has failed).
// Under no circumstance do we want these to be written to realm as null. // Under no circumstance do we want these to be written to realm as null.
if (model.BeatmapInfo == null) throw new ArgumentNullException(nameof(model.BeatmapInfo)); ArgumentNullException.ThrowIfNull(model.BeatmapInfo);
if (model.Ruleset == null) throw new ArgumentNullException(nameof(model.Ruleset)); ArgumentNullException.ThrowIfNull(model.Ruleset);
PopulateMaximumStatistics(model); PopulateMaximumStatistics(model);

View File

@ -147,7 +147,7 @@ namespace osu.Game.Screens.Menu
private void addAmplitudesFromSource(IHasAmplitudes source) private void addAmplitudesFromSource(IHasAmplitudes source)
{ {
if (source == null) throw new ArgumentNullException(nameof(source)); ArgumentNullException.ThrowIfNull(source);
var amplitudes = source.CurrentAmplitudes.FrequencyAmplitudes.Span; var amplitudes = source.CurrentAmplitudes.FrequencyAmplitudes.Span;

View File

@ -33,8 +33,7 @@ namespace osu.Game.Screens.Play.HUD
get => current.Current; get => current.Current;
set set
{ {
if (value == null) ArgumentNullException.ThrowIfNull(value);
throw new ArgumentNullException(nameof(value));
current.Current = value; current.Current = value;
} }

View File

@ -30,8 +30,7 @@ namespace osu.Game.Screens.Play.HUD
get => current.Current; get => current.Current;
set set
{ {
if (value == null) ArgumentNullException.ThrowIfNull(value);
throw new ArgumentNullException(nameof(value));
current.Current = value; current.Current = value;
} }

View File

@ -54,7 +54,7 @@ namespace osu.Game.Screens.Play
public override void Add(KeyCounter key) public override void Add(KeyCounter key)
{ {
if (key == null) throw new ArgumentNullException(nameof(key)); ArgumentNullException.ThrowIfNull(key);
base.Add(key); base.Add(key);
key.IsCounting = IsCounting; key.IsCounting = IsCounting;

View File

@ -27,8 +27,7 @@ namespace osu.Game.Users.Drawables
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(TextureStore ts) private void load(TextureStore ts)
{ {
if (ts == null) ArgumentNullException.ThrowIfNull(ts);
throw new ArgumentNullException(nameof(ts));
string textureName = countryCode == CountryCode.Unknown ? "__" : countryCode.ToString(); string textureName = countryCode == CountryCode.Unknown ? "__" : countryCode.ToString();
Texture = ts.Get($@"Flags/{textureName}") ?? ts.Get(@"Flags/__"); Texture = ts.Get($@"Flags/{textureName}") ?? ts.Get(@"Flags/__");

View File

@ -36,8 +36,7 @@ namespace osu.Game.Users
protected UserPanel(APIUser user) protected UserPanel(APIUser user)
: base(HoverSampleSet.Button) : base(HoverSampleSet.Button)
{ {
if (user == null) ArgumentNullException.ThrowIfNull(user);
throw new ArgumentNullException(nameof(user));
User = user; User = user;
} }