using System.Collections.Generic; using System.Xml.Serialization; using Newtonsoft.Json; using SabreTools.Core; namespace SabreTools.DatItems.Formats { /// /// Represents a single port on a machine /// [JsonObject("port"), XmlRoot("port")] public class Port : DatItem { #region Fields /// /// Tag for the port /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")] public string Tag { get; set; } /// /// List of analogs on the port /// [JsonProperty("analogs", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("analogs")] public List Analogs { get; set; } [JsonIgnore] public bool AnalogsSpecified { get { return Analogs != null && Analogs.Count > 0; } } #endregion #region Constructors /// /// Create a default, empty Port object /// 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 bool match = (Tag == newOther.Tag); if (!match) return match; // If the analogs match if (AnalogsSpecified) { foreach (Analog analog in Analogs) { match &= newOther.Analogs.Contains(analog); } } return match; } #endregion } }