From 0857dd6771938a864c31eef891974320a3342c98 Mon Sep 17 00:00:00 2001 From: James Groom Date: Wed, 20 Mar 2024 22:19:57 +0000 Subject: [PATCH] Clean up equality implementation for `Cell` --- .../CustomControls/InputRoll/Cell.cs | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/Cell.cs b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/Cell.cs index 40d235b8f1..bae344b07f 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/Cell.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/Cell.cs @@ -9,7 +9,7 @@ namespace BizHawk.Client.EmuHawk /// /// Represents a single cell of the /// - public sealed class Cell : IComparable + public sealed class Cell : IComparable, IEquatable { public RollColumn Column { get; internal set; } public int? RowIndex { get; internal set; } @@ -25,15 +25,11 @@ namespace BizHawk.Client.EmuHawk public int CompareTo(Cell other) => SortCell.Compare(this, other); - public override bool Equals(object obj) - { - if (obj is Cell cell) - { - return Column == cell.Column && RowIndex == cell.RowIndex; - } + public bool Equals(Cell other) + => other is not null && Column?.Name == other.Column?.Name && RowIndex == other.RowIndex; - return false; - } + public override bool Equals(object obj) + => obj is Cell other && Equals(other); public override int GetHashCode() { @@ -44,14 +40,10 @@ namespace BizHawk.Client.EmuHawk => $"Cell(r: {RowIndex?.ToString() ?? "null"}, c: \"{Column?.Name ?? "(no column)"}\")"; public static bool operator ==(Cell a, Cell b) - { - return a?.Equals(b) ?? b is null; - } + => a is null ? b is null : a.Equals(b); public static bool operator !=(Cell a, Cell b) - { - return !(a == b); - } + => a is null ? b is not null : !a.Equals(b); } internal static class SortCell