mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Be more explicit with DatItem CompareTo
This commit is contained in:
@@ -157,14 +157,18 @@ namespace SabreTools.DatItems
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public int CompareTo(DatItem? other)
|
public int CompareTo(DatItem? other)
|
||||||
{
|
{
|
||||||
|
// If the other item doesn't exist
|
||||||
|
if (other == null)
|
||||||
|
return 1;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (GetName() == other?.GetName())
|
if (GetName() == other.GetName())
|
||||||
return Equals(other) ? 0 : 1;
|
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
|
// 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
|
catch
|
||||||
{
|
{
|
||||||
@@ -545,14 +549,18 @@ namespace SabreTools.DatItems
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public int CompareTo(DatItem<T>? other)
|
public int CompareTo(DatItem<T>? other)
|
||||||
{
|
{
|
||||||
|
// If the other item doesn't exist
|
||||||
|
if (other == null)
|
||||||
|
return 1;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (GetName() == other?.GetName())
|
if (GetName() == other.GetName())
|
||||||
return Equals(other) ? 0 : 1;
|
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
|
// 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
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user