using System.Collections.Generic; using System.Linq; using System.Xml.Serialization; using Newtonsoft.Json; using SabreTools.Core; namespace SabreTools.DatItems.Formats { /// /// SoftwareList part information /// /// One Part can contain multiple PartFeature, DataArea, DiskArea, and DipSwitch items [JsonObject("part"), XmlRoot("part")] public class Part : DatItem { #region Fields [JsonProperty("interface"), XmlElement("interface")] public string? Interface { get => _internal.ReadString(Models.Metadata.Part.InterfaceKey); set => _internal[Models.Metadata.Part.InterfaceKey] = value; } [JsonProperty("features", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("features")] public List? Features { get => _internal.Read(Models.Metadata.Part.FeatureKey)?.ToList(); set => _internal[Models.Metadata.Part.FeatureKey] = value?.ToArray(); } [JsonIgnore] public bool FeaturesSpecified { get { return Features != null && Features.Count > 0; } } #endregion #region Accessors /// public override string? GetName() => GetFieldValue(Models.Metadata.Part.NameKey); /// public override void SetName(string? name) => SetFieldValue(Models.Metadata.Part.NameKey, name); #endregion #region Constructors /// /// Create a default, empty Part object /// public Part() { _internal = new Models.Metadata.Part(); Machine = new Machine(); SetName(string.Empty); ItemType = ItemType.Part; } #endregion #region Cloning Methods /// public override object Clone() { return new Part() { ItemType = this.ItemType, DupeType = this.DupeType, Machine = this.Machine.Clone() as Machine ?? new Machine(), Source = this.Source?.Clone() as Source, Remove = this.Remove, _internal = this._internal?.Clone() as Models.Metadata.Part ?? [], }; } #endregion } }