Files
SabreTools/SabreTools.DatItems/Formats/Device.cs

84 lines
2.0 KiB
C#
Raw Normal View History

2024-03-09 21:34:26 -05:00
using System.Xml.Serialization;
2020-09-02 17:09:19 -07:00
using Newtonsoft.Json;
2022-11-03 12:22:17 -07:00
using SabreTools.Core;
2020-09-02 17:09:19 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
2020-09-02 17:09:19 -07:00
{
/// <summary>
/// Represents a single device on the machine
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("device"), XmlRoot("device")]
2020-09-02 17:09:19 -07:00
public class Device : DatItem
{
#region Fields
2020-09-07 22:00:02 -07:00
[JsonIgnore]
2024-03-09 21:34:26 -05:00
public bool InstancesSpecified
{
2024-03-09 21:34:26 -05:00
get
{
var instances = GetFieldValue<Instance[]?>(Models.Metadata.Device.InstanceKey);
return instances != null && instances.Length > 0;
}
}
2020-09-02 17:09:19 -07:00
2020-09-07 22:00:02 -07:00
[JsonIgnore]
2024-03-09 21:34:26 -05:00
public bool ExtensionsSpecified
{
2024-03-09 21:34:26 -05:00
get
{
var extensions = GetFieldValue<Extension[]?>(Models.Metadata.Device.ExtensionKey);
return extensions != null && extensions.Length > 0;
}
}
2020-09-02 17:09:19 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Device object
/// </summary>
public Device()
{
2023-09-04 23:51:37 -04:00
_internal = new Models.Metadata.Device();
2023-08-15 01:38:01 -04:00
Machine = new Machine();
2020-09-02 17:09:19 -07:00
ItemType = ItemType.Device;
}
2024-03-09 21:46:38 -05:00
/// <summary>
/// Create a Device object from the internal model
/// </summary>
public Device(Models.Metadata.Device? item)
{
_internal = item ?? [];
Machine = new Machine();
ItemType = ItemType.Device;
}
2020-09-02 17:09:19 -07:00
#endregion
#region Cloning Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2020-09-02 17:09:19 -07:00
public override object Clone()
{
return new Device()
{
ItemType = this.ItemType,
DupeType = this.DupeType,
2023-08-15 01:38:01 -04:00
Machine = this.Machine.Clone() as Machine ?? new Machine(),
Source = this.Source?.Clone() as Source,
2020-09-02 17:09:19 -07:00
Remove = this.Remove,
2024-02-28 19:19:50 -05:00
_internal = this._internal?.Clone() as Models.Metadata.Device ?? [],
2020-09-02 17:09:19 -07:00
};
}
#endregion
}
}