Files
SabreTools/SabreTools.DatItems/Port.cs

99 lines
2.4 KiB
C#
Raw Normal View History

2020-09-02 17:22:31 -07:00
using System.Collections.Generic;
2020-09-07 22:00:02 -07:00
using System.Xml.Serialization;
2020-09-02 17:22:31 -07:00
2020-12-08 13:23:59 -08:00
using SabreTools.Core;
2020-09-02 17:22:31 -07:00
using Newtonsoft.Json;
2020-12-08 15:15:41 -08:00
namespace SabreTools.DatItems
2020-09-02 17:22:31 -07:00
{
/// <summary>
/// Represents a single port on a machine
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("port"), XmlRoot("port")]
2020-09-02 17:22:31 -07:00
public class Port : DatItem
{
#region Fields
/// <summary>
/// Tag for the port
/// </summary>
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("tag")]
2020-09-02 17:22:31 -07:00
public string Tag { get; set; }
/// <summary>
/// List of analogs on the port
/// </summary>
[JsonProperty("analogs", DefaultValueHandling = DefaultValueHandling.Ignore)]
2020-09-07 22:00:02 -07:00
[XmlElement("analogs")]
2020-09-02 17:22:31 -07:00
public List<Analog> Analogs { get; set; }
2020-09-07 22:00:02 -07:00
[JsonIgnore]
public bool AnalogsSpecified { get { return Analogs != null && Analogs.Count > 0; } }
2020-09-02 17:22:31 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Port object
/// </summary>
public Port()
{
ItemType = ItemType.Port;
}
#endregion
#region Cloning Methods
public override object Clone()
{
return new Port()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
Machine = this.Machine.Clone() as Machine,
Source = this.Source.Clone() as Source,
Remove = this.Remove,
Tag = this.Tag,
Analogs = this.Analogs,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)
{
// If we don't have a Port, return false
if (ItemType != other.ItemType)
return false;
// Otherwise, treat it as a Port
Port newOther = other as Port;
// If the Port information matches
2020-09-03 15:02:59 -07:00
bool match = (Tag == newOther.Tag);
if (!match)
return match;
// If the analogs match
2020-09-30 13:25:40 -07:00
if (AnalogsSpecified)
2020-09-03 15:02:59 -07:00
{
foreach (Analog analog in Analogs)
{
match &= newOther.Analogs.Contains(analog);
}
}
return match;
2020-09-02 17:22:31 -07:00
}
#endregion
}
}