Files
SabreTools/SabreTools.DatItems/Formats/Port.cs

67 lines
1.6 KiB
C#
Raw Normal View History

2024-03-09 21:34:26 -05:00
using System.Xml.Serialization;
2020-09-02 17:22:31 -07:00
using Newtonsoft.Json;
2022-11-03 12:22:17 -07:00
using SabreTools.Core;
2020-09-02 17:22:31 -07:00
2021-02-02 10:23:43 -08:00
namespace SabreTools.DatItems.Formats
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
2024-03-09 21:34:26 -05:00
[JsonIgnore]
public bool AnalogsSpecified
{
2024-03-09 21:34:26 -05:00
get
{
var analogs = GetFieldValue<Analog[]?>(Models.Metadata.Port.AnalogKey);
return analogs != null && analogs.Length > 0;
}
}
2020-09-02 17:22:31 -07:00
#endregion
#region Constructors
/// <summary>
/// Create a default, empty Port object
/// </summary>
public Port()
{
2023-09-04 23:51:37 -04:00
_internal = new Models.Metadata.Port();
2023-08-15 01:38:01 -04:00
2024-03-10 16:49:07 -04:00
SetFieldValue<ItemType>(Models.Metadata.DatItem.TypeKey, ItemType.Port);
SetFieldValue<Machine>(DatItem.MachineKey, new Machine());
2020-09-02 17:22:31 -07:00
}
2024-03-09 21:46:38 -05:00
/// <summary>
/// Create a Port object from the internal model
/// </summary>
public Port(Models.Metadata.Port? item)
{
_internal = item ?? [];
2024-03-10 16:49:07 -04:00
SetFieldValue<ItemType>(Models.Metadata.DatItem.TypeKey, ItemType.Port);
SetFieldValue<Machine>(DatItem.MachineKey, new Machine());
2024-03-09 21:46:38 -05:00
}
2020-09-02 17:22:31 -07:00
#endregion
#region Cloning Methods
2022-11-03 12:22:17 -07:00
/// <inheritdoc/>
2020-09-02 17:22:31 -07:00
public override object Clone()
{
return new Port()
{
2024-02-28 19:19:50 -05:00
_internal = this._internal?.Clone() as Models.Metadata.Port ?? [],
2020-09-02 17:22:31 -07:00
};
}
#endregion
}
}