From 18f73b985b82de1d0eb07a9e827ba53065330008 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Nov 2021 14:38:01 +0900 Subject: [PATCH] Make `ModelExtensions` nullable enabled --- osu.Game/Extensions/ModelExtensions.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/osu.Game/Extensions/ModelExtensions.cs b/osu.Game/Extensions/ModelExtensions.cs index 2545045d96..48a3bac112 100644 --- a/osu.Game/Extensions/ModelExtensions.cs +++ b/osu.Game/Extensions/ModelExtensions.cs @@ -7,6 +7,8 @@ using osu.Game.Rulesets; using osu.Game.Scoring; using osu.Game.Users; +#nullable enable + namespace osu.Game.Extensions { public static class ModelExtensions @@ -23,9 +25,9 @@ namespace osu.Game.Extensions /// extension method type inference rules cause this method to call itself and cause a stack overflow. /// /// - public static string GetDisplayString(this object model) + public static string GetDisplayString(this object? model) { - string result = null; + string? result = null; switch (model) { @@ -65,8 +67,11 @@ namespace osu.Game.Extensions /// The instance to compare. /// The other instance to compare against. /// Whether online IDs match. If either instance is missing an online ID, this will return false. - public static bool MatchesOnlineID(this IHasOnlineID instance, IHasOnlineID other) + public static bool MatchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) { + if (instance == null || other == null) + return false; + if (instance.OnlineID < 0 || other.OnlineID < 0) return false; @@ -79,8 +84,11 @@ namespace osu.Game.Extensions /// The instance to compare. /// The other instance to compare against. /// Whether online IDs match. If either instance is missing an online ID, this will return false. - public static bool MatchesOnlineID(this IHasOnlineID instance, IHasOnlineID other) + public static bool MatchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) { + if (instance == null || other == null) + return false; + if (instance.OnlineID < 0 || other.OnlineID < 0) return false;