mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-28 17:37:47 +00:00
This is both big and not big. The not big part of this is that I essentially just moved some stuff up to the typed type that used to live in the untyped type. The big part is that this allows every single DatItem implementation to be significantly cleaner with their implementations of the methods and internal model.
114 lines
3.0 KiB
C#
114 lines
3.0 KiB
C#
using System;
|
|
using System.Xml.Serialization;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace SabreTools.Metadata.DatItems.Formats
|
|
{
|
|
/// <summary>
|
|
/// SoftwareList diskarea information
|
|
/// </summary>
|
|
/// <remarks>One DiskArea can contain multiple Disk items</remarks>
|
|
[JsonObject("diskarea"), XmlRoot("diskarea")]
|
|
public sealed class DiskArea : DatItem<Data.Models.Metadata.DiskArea>
|
|
{
|
|
#region Properties
|
|
|
|
public Disk[]? Disk { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public bool DiskSpecified => Disk is not null && Disk.Length > 0;
|
|
|
|
/// <inheritdoc>/>
|
|
public override Data.Models.Metadata.ItemType ItemType
|
|
=> Data.Models.Metadata.ItemType.DiskArea;
|
|
|
|
public string? Name
|
|
{
|
|
get => _internal.Name;
|
|
set => _internal.Name = value;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public DiskArea() : base() { }
|
|
|
|
public DiskArea(Data.Models.Metadata.DiskArea item) : base(item)
|
|
{
|
|
// Handle subitems
|
|
if (item.Disk is not null)
|
|
Disk = Array.ConvertAll(item.Disk, rom => new Disk(rom));
|
|
}
|
|
|
|
public DiskArea(Data.Models.Metadata.DiskArea item, Machine machine, Source source) : this(item)
|
|
{
|
|
Source = source;
|
|
CopyMachineInformation(machine);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Accessors
|
|
|
|
/// <inheritdoc/>
|
|
public override string? GetName() => Name;
|
|
|
|
/// <inheritdoc/>
|
|
public override void SetName(string? name) => Name = name;
|
|
|
|
#endregion
|
|
|
|
#region Cloning Methods
|
|
|
|
/// <inheritdoc/>
|
|
public override object Clone() => new DiskArea(GetInternalClone());
|
|
|
|
public override Data.Models.Metadata.DiskArea GetInternalClone()
|
|
{
|
|
var partItem = _internal.Clone() as Data.Models.Metadata.DiskArea ?? new();
|
|
|
|
if (Disk is not null)
|
|
partItem.Disk = Array.ConvertAll(Disk, rom => rom.GetInternalClone());
|
|
|
|
return partItem;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Comparision Methods
|
|
|
|
/// <inheritdoc/>
|
|
public override bool Equals(DatItem? other)
|
|
{
|
|
// If the other item is null
|
|
if (other is null)
|
|
return false;
|
|
|
|
// If the type matches
|
|
if (other is DiskArea otherDiskArea)
|
|
return _internal.Equals(otherDiskArea._internal);
|
|
|
|
// Everything else fails
|
|
return false;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override bool Equals(DatItem<Data.Models.Metadata.DiskArea>? other)
|
|
{
|
|
// If the other value is invalid
|
|
if (other is null)
|
|
return false;
|
|
|
|
// If the type matches
|
|
if (other is DiskArea otherDiskArea)
|
|
return _internal.Equals(otherDiskArea._internal);
|
|
|
|
// Everything else fails
|
|
return false;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|