From f778735b96f22c2c8559c5c38ff62045144d2b45 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 7 Jan 2025 20:21:26 -0500 Subject: [PATCH] Be more explicit with DatItem CompareTo --- SabreTools.DatItems/DatItem.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/SabreTools.DatItems/DatItem.cs b/SabreTools.DatItems/DatItem.cs index 5d9a0dc0..8212f182 100644 --- a/SabreTools.DatItems/DatItem.cs +++ b/SabreTools.DatItems/DatItem.cs @@ -157,14 +157,18 @@ namespace SabreTools.DatItems /// public int CompareTo(DatItem? other) { + // If the other item doesn't exist + if (other == null) + return 1; + try { - if (GetName() == other?.GetName()) - return Equals(other) ? 0 : 1; + if (GetName() == other.GetName()) + return Equals(other) ? 0 : (other.ItemType - ItemType); - // If `other?.GetName()` is null, Compare will return > 0 + // If `other.GetName()` is null, Compare will return > 0 // If `this.GetName()` is null, Compare will return < 0 - return string.Compare(GetName(), other?.GetName(), StringComparison.Ordinal); + return string.Compare(GetName(), other.GetName(), StringComparison.Ordinal); } catch { @@ -545,14 +549,18 @@ namespace SabreTools.DatItems /// public int CompareTo(DatItem? other) { + // If the other item doesn't exist + if (other == null) + return 1; + try { - if (GetName() == other?.GetName()) - return Equals(other) ? 0 : 1; + if (GetName() == other.GetName()) + return Equals(other) ? 0 : (other.ItemType - ItemType); // If `other?.GetName()` is null, Compare will return > 0 // If `this.GetName()` is null, Compare will return < 0 - return string.Compare(GetName(), other?.GetName(), StringComparison.Ordinal); + return string.Compare(GetName(), other.GetName(), StringComparison.Ordinal); } catch {