// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Game.Beatmaps; using osu.Game.Rulesets; using osu.Game.Scoring; using osu.Game.Users; namespace osu.Game.Extensions { public static class ModelExtensions { /// /// Returns a user-facing string representing the . /// /// /// /// Non-interface types without special handling will fall back to . /// /// /// Warning: This method is _purposefully_ not called GetDisplayTitle() like the others, because otherwise /// extension method type inference rules cause this method to call itself and cause a stack overflow. /// /// public static string GetDisplayString(this object model) { string result = null; switch (model) { case IBeatmapSetInfo beatmapSetInfo: result = beatmapSetInfo.Metadata?.GetDisplayTitle(); break; case IBeatmapInfo beatmapInfo: result = beatmapInfo.GetDisplayTitle(); break; case IBeatmapMetadataInfo metadataInfo: result = metadataInfo.GetDisplayTitle(); break; case IScoreInfo scoreInfo: result = scoreInfo.GetDisplayTitle(); break; case IRulesetInfo rulesetInfo: result = rulesetInfo.Name; break; case IUser user: result = user.Username; break; } // fallback in case none of the above happens to match. result ??= model?.ToString() ?? @"null"; return result; } } }