Files

72 lines
2.1 KiB
C#
Raw Permalink Normal View History

using System;
2025-09-26 10:20:48 -04:00
using System.Xml.Serialization;
using Newtonsoft.Json;
2025-09-26 13:06:18 -04:00
namespace SabreTools.Data.Models.Metadata
2025-09-26 10:20:48 -04:00
{
[JsonObject("part"), XmlRoot("part")]
public class Part : DatItem, ICloneable, IEquatable<Part>
2025-09-26 10:20:48 -04:00
{
2026-04-01 13:18:45 -04:00
#region Properties
public DataArea[]? DataArea { get; set; }
public DiskArea[]? DiskArea { get; set; }
public DipSwitch[]? DipSwitch { get; set; }
public Feature[]? Feature { get; set; }
2026-04-02 14:28:46 -04:00
public string? Interface { get; set; }
2026-04-01 13:18:45 -04:00
public string? Name { get; set; }
#endregion
public Part() => ItemType = ItemType.Part;
2025-09-26 10:20:48 -04:00
/// <inheritdoc/>
public object Clone()
{
var obj = new Part();
2025-09-26 10:20:48 -04:00
if (DataArea is not null)
obj.DataArea = Array.ConvertAll(DataArea, i => (DataArea)i.Clone());
if (DiskArea is not null)
obj.DiskArea = Array.ConvertAll(DiskArea, i => (DiskArea)i.Clone());
if (DipSwitch is not null)
obj.DipSwitch = Array.ConvertAll(DipSwitch, i => (DipSwitch)i.Clone());
if (Feature is not null)
obj.Feature = Array.ConvertAll(Feature, i => (Feature)i.Clone());
obj.Interface = Interface;
obj.Name = Name;
2025-09-26 10:20:48 -04:00
return obj;
}
2025-09-26 10:20:48 -04:00
/// <inheritdoc/>
public bool Equals(Part? other)
{
// Null never matches
if (other is null)
return false;
2025-09-26 10:20:48 -04:00
// Properties
if ((Interface is null) ^ (other.Interface is null))
return false;
else if (Interface is not null && !Interface.Equals(other.Interface, StringComparison.OrdinalIgnoreCase))
return false;
2025-09-26 10:20:48 -04:00
if ((Name is null) ^ (other.Name is null))
return false;
else if (Name is not null && !Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase))
return false;
// Sub-items
// TODO: Figure out how to properly check arrays
return true;
}
2025-09-26 10:20:48 -04:00
}
}