Help internal migration of models

This commit is contained in:
Matt Nadareski
2025-05-02 15:47:26 -04:00
parent edee5cd99b
commit 04adbb17df
40 changed files with 116 additions and 139 deletions

View File

@@ -8,21 +8,131 @@ namespace SabreTools.Core
{
public static class DictionaryBaseExtensions
{
#region Accessors
/// <summary>
/// Gets the name to use for a DictionaryBase or null
/// </summary>
public static string? GetName(this DictionaryBase self)
{
if (self == null)
return null;
return self switch
{
Machine => self.ReadString(Machine.NameKey),
Adjuster => self.ReadString(Adjuster.NameKey),
Analog => null,
Archive => self.ReadString(Archive.NameKey),
BiosSet => self.ReadString(BiosSet.NameKey),
Chip => self.ReadString(Chip.NameKey),
Condition => null,
ConfLocation => self.ReadString(ConfLocation.NameKey),
ConfSetting => self.ReadString(ConfSetting.NameKey),
Configuration => self.ReadString(Configuration.NameKey),
Control => null,
DataArea => self.ReadString(DataArea.NameKey),
Device => null,
DeviceRef => self.ReadString(DeviceRef.NameKey),
DipLocation => self.ReadString(DipLocation.NameKey),
DipSwitch => self.ReadString(DipSwitch.NameKey),
DipValue => self.ReadString(DipValue.NameKey),
Disk => self.ReadString(Disk.NameKey),
DiskArea => self.ReadString(DiskArea.NameKey),
Display => null,
Driver => null,
Extension => self.ReadString(Extension.NameKey),
Feature => self.ReadString(Feature.NameKey),
Info => self.ReadString(Info.NameKey),
Input => null,
Instance => self.ReadString(Instance.NameKey),
Media => self.ReadString(Media.NameKey),
Part => self.ReadString(Part.NameKey),
Port => null,
RamOption => self.ReadString(RamOption.NameKey),
Release => self.ReadString(Release.NameKey),
Rom => self.ReadString(Rom.NameKey),
Sample => self.ReadString(Sample.NameKey),
SharedFeat => self.ReadString(SharedFeat.NameKey),
Slot => self.ReadString(Slot.NameKey),
SlotOption => self.ReadString(SlotOption.NameKey),
SoftwareList => self.ReadString(SoftwareList.NameKey),
Sound => null,
_ => null,
};
}
/// <summary>
/// Gets the name to use for a DictionaryBase or null
/// </summary>
public static void SetName(this DictionaryBase self, string? name)
{
if (self == null || string.IsNullOrEmpty(name))
return;
switch (self)
{
case Machine: self[Machine.NameKey] = name; break;
case Adjuster: self[Adjuster.NameKey] = name; break;
case Analog: break;
case Archive: self[Archive.NameKey] = name; break;
case BiosSet: self[BiosSet.NameKey] = name; break;
case Chip: self[Chip.NameKey] = name; break;
case Condition: break;
case ConfLocation: self[ConfLocation.NameKey] = name; break;
case ConfSetting: self[ConfSetting.NameKey] = name; break;
case Configuration: self[Configuration.NameKey] = name; break;
case Control: break;
case DataArea: self[DataArea.NameKey] = name; break;
case Device: break;
case DeviceRef: self[DeviceRef.NameKey] = name; break;
case DipLocation: self[DipLocation.NameKey] = name; break;
case DipSwitch: self[DipSwitch.NameKey] = name; break;
case DipValue: self[DipValue.NameKey] = name; break;
case Disk: self[Disk.NameKey] = name; break;
case DiskArea: self[DiskArea.NameKey] = name; break;
case Display: break;
case Driver: break;
case Extension: self[Extension.NameKey] = name; break;
case Feature: self[Feature.NameKey] = name; break;
case Info: self[Info.NameKey] = name; break;
case Input: break;
case Instance: self[Instance.NameKey] = name; break;
case Media: self[Media.NameKey] = name; break;
case Part: self[Part.NameKey] = name; break;
case Port: break;
case RamOption: self[RamOption.NameKey] = name; break;
case Release: self[Release.NameKey] = name; break;
case Rom: self[Rom.NameKey] = name; break;
case Sample: self[Sample.NameKey] = name; break;
case SharedFeat: self[SharedFeat.NameKey] = name; break;
case Slot: self[Slot.NameKey] = name; break;
case SlotOption: self[SlotOption.NameKey] = name; break;
case SoftwareList: self[SoftwareList.NameKey] = name; break;
case Sound: break;
}
}
#endregion
#region Cloning
/// <summary>
/// Deep clone a DictionaryBase object
/// </summary>
public static DictionaryBase? Clone(this DictionaryBase dictionaryBase)
public static DictionaryBase? Clone(this DictionaryBase self)
{
// If construction failed, we can't do anything
if (Activator.CreateInstance(dictionaryBase.GetType()) is not DictionaryBase clone)
if (Activator.CreateInstance(self.GetType()) is not DictionaryBase clone)
return null;
// Loop through and clone per type
foreach (string key in dictionaryBase.Keys)
foreach (string key in self.Keys)
{
object? value = dictionaryBase[key];
object? value = self[key];
clone[key] = value switch
{
// Primative types

View File

@@ -520,15 +520,6 @@ namespace SabreTools.DatItems
/// </summary>
public abstract class DatItem<T> : DatItem, IEquatable<DatItem<T>>, IComparable<DatItem<T>>, ICloneable where T : Models.Metadata.DatItem
{
#region Fields
/// <summary>
/// Key for accessing the item name, if it exists
/// </summary>
protected abstract string? NameKey { get; }
#endregion
#region Constructors
/// <summary>
@@ -559,20 +550,10 @@ namespace SabreTools.DatItems
#region Accessors
/// <inheritdoc/>
public override string? GetName()
{
if (!string.IsNullOrEmpty(NameKey))
return GetStringFieldValue(NameKey);
return null;
}
public override string? GetName() => _internal.GetName();
/// <inheritdoc/>
public override void SetName(string? name)
{
if (!string.IsNullOrEmpty(NameKey))
SetFieldValue(NameKey, name);
}
public override void SetName(string? name) => _internal.SetName(name);
#endregion

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Adjuster;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Adjuster.NameKey;
[JsonIgnore]
public bool ConditionsSpecified
{

View File

@@ -14,9 +14,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Analog;
/// <inheritdoc>/>
protected override string? NameKey => null;
#endregion
#region Constructors

View File

@@ -14,9 +14,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Archive;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Archive.NameKey;
// TODO: None of the following are used or checked
/// <summary>

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.BiosSet;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.BiosSet.NameKey;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Chip;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Chip.NameKey;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Condition;
/// <inheritdoc>/>
protected override string? NameKey => null;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.ConfLocation;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.ConfLocation.NameKey;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.ConfSetting;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.ConfSetting.NameKey;
[JsonIgnore]
public bool ConditionsSpecified
{

View File

@@ -16,9 +16,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Configuration;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Configuration.NameKey;
[JsonIgnore]
public bool ConditionsSpecified
{

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Control;
/// <inheritdoc>/>
protected override string? NameKey => null;
#endregion
#region Constructors

View File

@@ -16,9 +16,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.DataArea;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.DataArea.NameKey;
#endregion
#region Constructors

View File

@@ -17,9 +17,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Device;
/// <inheritdoc>/>
protected override string? NameKey => null;
[JsonIgnore]
public bool InstancesSpecified
{

View File

@@ -14,9 +14,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.DeviceRef;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.DeviceRef.NameKey;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.DipLocation;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.DipLocation.NameKey;
#endregion
#region Constructors

View File

@@ -26,9 +26,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.DipSwitch;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.DipSwitch.NameKey;
[JsonIgnore]
public bool ConditionsSpecified
{

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.DipValue;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.DipValue.NameKey;
[JsonIgnore]
public bool ConditionsSpecified
{

View File

@@ -30,9 +30,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Disk;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Disk.NameKey;
[JsonIgnore]
public bool DiskAreaSpecified
{

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.DiskArea;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.DiskArea.NameKey;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Display;
/// <inheritdoc>/>
protected override string? NameKey => null;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Driver;
/// <inheritdoc>/>
protected override string? NameKey => null;
#endregion
#region Constructors

View File

@@ -14,9 +14,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Extension;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Extension.NameKey;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Feature;
/// <inheritdoc>/>
protected override string? NameKey => null;
#endregion
#region Constructors

View File

@@ -14,9 +14,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Info;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Instance.NameKey;
#endregion
#region Constructors

View File

@@ -17,9 +17,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Input;
/// <inheritdoc>/>
protected override string? NameKey => null;
[JsonIgnore]
public bool ControlsSpecified
{

View File

@@ -14,9 +14,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Instance;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Instance.NameKey;
#endregion
#region Constructors

View File

@@ -16,9 +16,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Media;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Media.NameKey;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Part;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Part.NameKey;
[JsonIgnore]
public bool FeaturesSpecified
{

View File

@@ -24,9 +24,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.PartFeature;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Feature.NameKey;
#endregion
#region Constructors

View File

@@ -16,9 +16,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Port;
/// <inheritdoc>/>
protected override string? NameKey => null;
[JsonIgnore]
public bool AnalogsSpecified
{

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.RamOption;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.RamOption.NameKey;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Release;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Release.NameKey;
#endregion
#region Constructors

View File

@@ -30,9 +30,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Rom;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Rom.NameKey;
[JsonIgnore]
public bool ItemStatusSpecified
{

View File

@@ -14,9 +14,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Sample;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Sample.NameKey;
#endregion
#region Constructors

View File

@@ -14,9 +14,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.SharedFeat;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.SharedFeat.NameKey;
#endregion
#region Constructors

View File

@@ -16,9 +16,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Slot;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.Slot.NameKey;
[JsonIgnore]
public bool SlotOptionsSpecified
{

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.SlotOption;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.SlotOption.NameKey;
#endregion
#region Constructors

View File

@@ -15,9 +15,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.SoftwareList;
/// <inheritdoc>/>
protected override string? NameKey => Models.Metadata.SoftwareList.NameKey;
#endregion
#region Constructors

View File

@@ -14,9 +14,6 @@ namespace SabreTools.DatItems.Formats
/// <inheritdoc>/>
protected override ItemType ItemType => ItemType.Sound;
/// <inheritdoc>/>
protected override string? NameKey => null;
#endregion
#region Constructors