Add RulesetInfo hashcode implementation and tidy up equality

This commit is contained in:
Dean Herbert
2022-01-10 16:31:50 +09:00
parent c33e163178
commit 5cbd731864
2 changed files with 25 additions and 6 deletions

View File

@ -47,14 +47,25 @@ namespace osu.Game.Rulesets
public bool Available { get; set; }
public bool Equals(RulesetInfo? other) => other != null
&& OnlineID == other.OnlineID
&& Available == other.Available
&& Name == other.Name
&& InstantiationInfo == other.InstantiationInfo;
public bool Equals(RulesetInfo? other)
{
if (ReferenceEquals(this, other)) return true;
if (other == null) return false;
return ShortName == other.ShortName;
}
public bool Equals(IRulesetInfo? other) => other is RulesetInfo b && Equals(b);
public override int GetHashCode()
{
// Importantly, ignore the underlying realm hash code, as it will usually not match.
var hashCode = new HashCode();
// ReSharper disable once NonReadonlyMemberInGetHashCode
hashCode.Add(ShortName);
return hashCode.ToHashCode();
}
public override string ToString() => Name;
public RulesetInfo Clone() => new RulesetInfo