1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 13:37:51 +08:00
osu-lazer/osu.Game/Online/Spectator/SpectatorState.cs
Bartłomiej Dach aaa7c7eb05 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`.
2021-05-14 23:58:07 +02:00

38 lines
1.1 KiB
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using MessagePack;
using osu.Game.Online.API;
namespace osu.Game.Online.Spectator
{
[Serializable]
[MessagePackObject]
public class SpectatorState : IEquatable<SpectatorState>
{
[Key(0)]
public int? BeatmapID { get; set; }
[Key(1)]
public int? RulesetID { get; set; }
[NotNull]
[Key(2)]
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
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}";
}
}