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
{