Use extension method to compare online IDs

This commit is contained in:
Dean Herbert
2021-11-15 14:34:50 +09:00
parent 9f7e2750a5
commit a4c11e8813
3 changed files with 34 additions and 1 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Users;
@ -57,5 +58,33 @@ namespace osu.Game.Extensions
result ??= model?.ToString() ?? @"null";
return result;
}
/// <summary>
/// Check whether the online ID of two instances match.
/// </summary>
/// <param name="instance">The instance to compare.</param>
/// <param name="other">The other instance to compare against.</param>
/// <returns>Whether online IDs match. If either instance is missing an online ID, this will return false.</returns>
public static bool MatchesOnlineID(this IHasOnlineID<long> instance, IHasOnlineID<long> other)
{
if (instance.OnlineID < 0 || other.OnlineID < 0)
return false;
return instance.OnlineID.Equals(other.OnlineID);
}
/// <summary>
/// Check whether the online ID of two instances match.
/// </summary>
/// <param name="instance">The instance to compare.</param>
/// <param name="other">The other instance to compare against.</param>
/// <returns>Whether online IDs match. If either instance is missing an online ID, this will return false.</returns>
public static bool MatchesOnlineID(this IHasOnlineID<int> instance, IHasOnlineID<int> other)
{
if (instance.OnlineID < 0 || other.OnlineID < 0)
return false;
return instance.OnlineID.Equals(other.OnlineID);
}
}
}