mirror of
https://github.com/ppy/osu
synced 2024-12-26 00:32:52 +00:00
Handle null case explicitly in SpectatorState.Equals()
Uses the usual pattern of two `ReferenceEquals` checks against `this` and `null` before proceeding to inspect field values. Doing this causes the compiler to infer that at the point that field values are checked, `other` can no longer viably be `null`.
This commit is contained in:
parent
044770f1a2
commit
aaa7c7eb05
@ -24,7 +24,13 @@ namespace osu.Game.Online.Spectator
|
||||
[Key(2)]
|
||||
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
|
||||
|
||||
public bool Equals(SpectatorState other) => BeatmapID == other?.BeatmapID && Mods.SequenceEqual(other?.Mods) && RulesetID == other?.RulesetID;
|
||||
public bool Equals(SpectatorState other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return BeatmapID == other.BeatmapID && Mods.SequenceEqual(other.Mods) && RulesetID == other.RulesetID;
|
||||
}
|
||||
|
||||
public override string ToString() => $"Beatmap:{BeatmapID} Mods:{string.Join(',', Mods)} Ruleset:{RulesetID}";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user