Make "simple" metadata items equatable

This commit is contained in:
Matt Nadareski
2026-04-02 16:07:34 -04:00
parent 1e27b5d720
commit ca95e96402
13 changed files with 274 additions and 13 deletions

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("analog"), XmlRoot("analog")]
public class Analog : DatItem, ICloneable
public class Analog : DatItem, ICloneable, IEquatable<Analog>
{
#region Properties
@@ -24,5 +24,21 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(Analog? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if ((Mask is null) ^ (other.Mask is null))
return false;
else if (Mask is not null && !Mask.Equals(other.Mask, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("biosset"), XmlRoot("biosset")]
public class BiosSet : DatItem, ICloneable
public class BiosSet : DatItem, ICloneable, IEquatable<BiosSet>
{
#region Properties
@@ -31,5 +31,29 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(BiosSet? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if (Default != other.Default)
return false;
if ((Description is null) ^ (other.Description is null))
return false;
else if (Description is not null && !Description.Equals(other.Description, StringComparison.OrdinalIgnoreCase))
return false;
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,11 +5,14 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("blank"), XmlRoot("blank")]
public class Blank : DatItem, ICloneable
public class Blank : DatItem, ICloneable, IEquatable<Blank>
{
public Blank() => ItemType = ItemType.Blank;
/// <inheritdoc/>
public object Clone() => new Blank();
/// <inheritdoc/>
public bool Equals(Blank? other) => other is not null;
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("condition"), XmlRoot("condition")]
public class Condition : DatItem, ICloneable
public class Condition : DatItem, ICloneable, IEquatable<Condition>
{
#region Properties
@@ -34,5 +34,34 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(Condition? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if ((Mask is null) ^ (other.Mask is null))
return false;
else if (Mask is not null && !Mask.Equals(other.Mask, StringComparison.OrdinalIgnoreCase))
return false;
if (Relation != other.Relation)
return false;
if ((Tag is null) ^ (other.Tag is null))
return false;
else if (Tag is not null && !Tag.Equals(other.Tag, StringComparison.OrdinalIgnoreCase))
return false;
if ((Value is null) ^ (other.Value is null))
return false;
else if (Value is not null && !Value.Equals(other.Value, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("device_ref"), XmlRoot("device_ref")]
public class DeviceRef : DatItem, ICloneable
public class DeviceRef : DatItem, ICloneable, IEquatable<DeviceRef>
{
#region Properties
@@ -24,5 +24,21 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(DeviceRef? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("extension"), XmlRoot("extension")]
public class Extension : DatItem, ICloneable
public class Extension : DatItem, ICloneable, IEquatable<Extension>
{
#region Properties
@@ -24,5 +24,21 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(Extension? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("feature"), XmlRoot("feature")]
public class Feature : DatItem, ICloneable
public class Feature : DatItem, ICloneable, IEquatable<Feature>
{
#region Properties
@@ -39,5 +39,35 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(Feature? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if (FeatureType != other.FeatureType)
return false;
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
if (Overall != other.Overall)
return false;
if (Status != other.Status)
return false;
if ((Value is null) ^ (other.Value is null))
return false;
else if (Value is not null && !Value.Equals(other.Value, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("info"), XmlRoot("info")]
public class Info : DatItem, ICloneable
public class Info : DatItem, ICloneable, IEquatable<Info>
{
#region Properties
@@ -27,5 +27,26 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(Info? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
if ((Value is null) ^ (other.Value is null))
return false;
else if (Value is not null && !Value.Equals(other.Value, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("instance"), XmlRoot("instance")]
public class Instance : DatItem, ICloneable
public class Instance : DatItem, ICloneable, IEquatable<Instance>
{
#region Properties
@@ -27,5 +27,26 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(Instance? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if ((BriefName is null) ^ (other.BriefName is null))
return false;
else if (BriefName is not null && !BriefName.Equals(other.BriefName, StringComparison.OrdinalIgnoreCase))
return false;
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("ramoption"), XmlRoot("ramoption")]
public class RamOption : DatItem, ICloneable
public class RamOption : DatItem, ICloneable, IEquatable<RamOption>
{
#region Properties
@@ -31,5 +31,29 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(RamOption? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if ((Content is null) ^ (other.Content is null))
return false;
else if (Content is not null && !Content.Equals(other.Content, StringComparison.OrdinalIgnoreCase))
return false;
if (Default != other.Default)
return false;
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("sample"), XmlRoot("sample")]
public class Sample : DatItem, ICloneable
public class Sample : DatItem, IEquatable<Sample>
{
#region Properties
@@ -24,5 +24,21 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(Sample? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("sharedfeat"), XmlRoot("sharedfeat")]
public class SharedFeat : DatItem, ICloneable
public class SharedFeat : DatItem, ICloneable, IEquatable<SharedFeat>
{
#region Properties
@@ -27,5 +27,26 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(SharedFeat? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
if ((Value is null) ^ (other.Value is null))
return false;
else if (Value is not null && !Value.Equals(other.Value, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}

View File

@@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace SabreTools.Data.Models.Metadata
{
[JsonObject("slotoption"), XmlRoot("slotoption")]
public class SlotOption : DatItem, ICloneable
public class SlotOption : DatItem, ICloneable, IEquatable<SlotOption>
{
#region Properties
@@ -31,5 +31,29 @@ namespace SabreTools.Data.Models.Metadata
return obj;
}
/// <inheritdoc/>
public bool Equals(SlotOption? other)
{
// Null never matches
if (other is null)
return false;
// Properties
if (Default != other.Default)
return false;
if ((DevName is null) ^ (other.DevName is null))
return false;
else if (DevName is not null && !DevName.Equals(other.DevName, StringComparison.OrdinalIgnoreCase))
return false;
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
return true;
}
}
}