mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Allow IRulesetInfo
s of same type to be comparable
At first I was planning on making `CompareTo` implemented at `IRulesetInfo` itself and shared across classes, but turns out it only implements it explicitly and not allow direct `IRulesetInfo.Equals` calls. It messed with my head enough that I decided to just let each class have its own implementation and only allow same type.
This commit is contained in:
@ -12,7 +12,7 @@ namespace osu.Game.Rulesets
|
||||
{
|
||||
[ExcludeFromDynamicCompile]
|
||||
[MapTo("Ruleset")]
|
||||
public class RulesetInfo : RealmObject, IEquatable<RulesetInfo>, IRulesetInfo
|
||||
public class RulesetInfo : RealmObject, IEquatable<RulesetInfo>, IComparable<RulesetInfo>, IRulesetInfo
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string ShortName { get; set; } = string.Empty;
|
||||
@ -47,7 +47,7 @@ namespace osu.Game.Rulesets
|
||||
return ShortName == other.ShortName;
|
||||
}
|
||||
|
||||
public bool Equals(IRulesetInfo? other) => other is RulesetInfo b && Equals(b);
|
||||
public bool Equals(IRulesetInfo? other) => other is RulesetInfo r && Equals(r);
|
||||
|
||||
public int CompareTo(RulesetInfo other)
|
||||
{
|
||||
@ -63,6 +63,14 @@ namespace osu.Game.Rulesets
|
||||
return string.Compare(ShortName, other.ShortName, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public int CompareTo(IRulesetInfo other)
|
||||
{
|
||||
if (!(other is RulesetInfo ruleset))
|
||||
throw new ArgumentException($@"Object is not of type {nameof(RulesetInfo)}.", nameof(other));
|
||||
|
||||
return CompareTo(ruleset);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
// Importantly, ignore the underlying realm hash code, as it will usually not match.
|
||||
|
Reference in New Issue
Block a user