mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Remove get/set name methods where appropriate
This commit is contained in:
@@ -10,132 +10,6 @@ namespace SabreTools.Data.Extensions
|
||||
// TODO: Combine yes/partial/no enums
|
||||
public static class MetadataExtensions
|
||||
{
|
||||
#region Accessors
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name to use for a DictionaryBase or null
|
||||
/// </summary>
|
||||
/// TODO: Determine if this can be removed
|
||||
public static string? GetName(this DictionaryBase self)
|
||||
{
|
||||
if (self is null)
|
||||
return null;
|
||||
|
||||
return self switch
|
||||
{
|
||||
Header header => header.Name,
|
||||
|
||||
Machine machine => machine.Name,
|
||||
|
||||
Adjuster adjuster => adjuster.Name,
|
||||
Analog => null,
|
||||
Archive archive => archive.Name,
|
||||
BiosSet biosSet => biosSet.Name,
|
||||
Chip chip => chip.Name,
|
||||
Condition => null,
|
||||
ConfLocation confLocation => confLocation.Name,
|
||||
ConfSetting confSetting => confSetting.Name,
|
||||
Configuration configuration => configuration.Name,
|
||||
Control => null,
|
||||
DataArea dataArea => dataArea.Name,
|
||||
Device => null,
|
||||
DeviceRef deviceRef => deviceRef.Name,
|
||||
DipLocation dipLocation => dipLocation.Name,
|
||||
DipSwitch dipSwitch => dipSwitch.Name,
|
||||
DipValue dipValue => dipValue.Name,
|
||||
Disk disk => disk.Name,
|
||||
DiskArea diskArea => diskArea.Name,
|
||||
Display => null,
|
||||
Driver => null,
|
||||
Extension extension => extension.Name,
|
||||
Feature feature => feature.Name,
|
||||
Info info => info.Name,
|
||||
Input => null,
|
||||
Instance instance => instance.Name,
|
||||
Media media => media.Name,
|
||||
Part part => part.Name,
|
||||
Port => null,
|
||||
RamOption ramOption => ramOption.Name,
|
||||
Release release => release.Name,
|
||||
ReleaseDetails => null,
|
||||
Rom rom => rom.Name,
|
||||
Sample sample => sample.Name,
|
||||
Serials => null,
|
||||
SharedFeat sharedFeat => sharedFeat.Name,
|
||||
Slot slot => slot.Name,
|
||||
SlotOption slotOption => slotOption.Name,
|
||||
SoftwareList softwareList => softwareList.Name,
|
||||
Sound => null,
|
||||
SourceDetails => null,
|
||||
Video => null,
|
||||
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name to use for a DictionaryBase or null
|
||||
/// </summary>
|
||||
/// TODO: Determine if this can be removed
|
||||
public static void SetName(this DictionaryBase self, string? name)
|
||||
{
|
||||
if (self is null || string.IsNullOrEmpty(name))
|
||||
return;
|
||||
|
||||
switch (self)
|
||||
{
|
||||
case Header header: header.Name = name; break;
|
||||
|
||||
case Machine machine: machine.Name = name; break;
|
||||
|
||||
case Adjuster adjuster: adjuster.Name = name; break;
|
||||
case Analog: break;
|
||||
case Archive archive: archive.Name = name; break;
|
||||
case BiosSet biosSet: biosSet.Name = name; break;
|
||||
case Chip chip: chip.Name = name; break;
|
||||
case Condition: break;
|
||||
case ConfLocation confLocation: confLocation.Name = name; break;
|
||||
case ConfSetting confSetting: confSetting.Name = name; break;
|
||||
case Configuration configuration: configuration.Name = name; break;
|
||||
case Control: break;
|
||||
case DataArea dataArea: dataArea.Name = name; break;
|
||||
case Device: break;
|
||||
case DeviceRef deviceRef: deviceRef.Name = name; break;
|
||||
case DipLocation dipLocation: dipLocation.Name = name; break;
|
||||
case DipSwitch dipSwitch: dipSwitch.Name = name; break;
|
||||
case DipValue dipValue: dipValue.Name = name; break;
|
||||
case Disk disk: disk.Name = name; break;
|
||||
case DiskArea diskArea: diskArea.Name = name; break;
|
||||
case Display: break;
|
||||
case Driver: break;
|
||||
case Extension extension: extension.Name = name; break;
|
||||
case Feature feature: feature.Name = name; break;
|
||||
case Info info: info.Name = name; break;
|
||||
case Input: break;
|
||||
case Instance instance: instance.Name = name; break;
|
||||
case Media media: media.Name = name; break;
|
||||
case Part part: part.Name = name; break;
|
||||
case Port: break;
|
||||
case RamOption ramOption: ramOption.Name = name; break;
|
||||
case Release release: release.Name = name; break;
|
||||
case ReleaseDetails: break;
|
||||
case Rom rom: rom.Name = name; break;
|
||||
case Sample sample: sample.Name = name; break;
|
||||
case Serials: break;
|
||||
case SharedFeat sharedFeat: sharedFeat.Name = name; break;
|
||||
case Slot slot: slot.Name = name; break;
|
||||
case SlotOption slotOption: slotOption.Name = name; break;
|
||||
case SoftwareList softwareList: softwareList.Name = name; break;
|
||||
case Sound: break;
|
||||
case SourceDetails: break;
|
||||
case Video: break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -59,7 +59,6 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Machine machine = new Machine();
|
||||
|
||||
var file = new File { SHA1 = "deadbeef" };
|
||||
file.SetName("item");
|
||||
|
||||
var dict = new ItemDictionaryDB();
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
@@ -78,7 +77,6 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Machine machine = new Machine();
|
||||
|
||||
DatItem file = new File();
|
||||
file.SetName("item");
|
||||
|
||||
var dict = new ItemDictionaryDB();
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
|
||||
@@ -67,7 +67,6 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Source = source,
|
||||
Machine = machine
|
||||
};
|
||||
file.SetName("item");
|
||||
|
||||
var dict = new ItemDictionary();
|
||||
_ = dict.AddItem(file, statsOnly: false);
|
||||
@@ -88,7 +87,6 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
Source = source,
|
||||
Machine = machine
|
||||
};
|
||||
file.SetName("item");
|
||||
|
||||
var dict = new ItemDictionary();
|
||||
_ = dict.AddItem(file, statsOnly: false);
|
||||
|
||||
@@ -510,16 +510,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
disk.Name = $"{pre}{name}{post}";
|
||||
}
|
||||
}
|
||||
else if (item is DatItems.Formats.File file)
|
||||
{
|
||||
// We can only write out if there's a SHA-1
|
||||
string? sha1 = file.SHA1;
|
||||
if (!string.IsNullOrEmpty(sha1))
|
||||
{
|
||||
name = Utilities.GetDepotPath(sha1, Modifiers.OutputDepot.Depth)?.Replace('\\', '/');
|
||||
file.SetName($"{pre}{name}{post}");
|
||||
}
|
||||
}
|
||||
else if (item is Media media)
|
||||
{
|
||||
// We can only write out if there's a SHA-1
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace SabreTools.Metadata.DatItems.Test
|
||||
|
||||
public string? Name
|
||||
{
|
||||
get => (_internal as Data.Models.Metadata.Info)?.Name;
|
||||
set => (_internal as Data.Models.Metadata.Info)?.Name = value;
|
||||
get => (_internal as TestDatItemModel)?.Name;
|
||||
set => (_internal as TestDatItemModel)?.Name = value;
|
||||
}
|
||||
|
||||
public TestDatItem() { }
|
||||
@@ -241,19 +241,6 @@ namespace SabreTools.Metadata.DatItems.Test
|
||||
Assert.True(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_MismatchedInternal_False()
|
||||
{
|
||||
DatItem self = new TestDatItem();
|
||||
self.SetName("self");
|
||||
|
||||
DatItem? other = new TestDatItem();
|
||||
other.SetName("other");
|
||||
|
||||
bool actual = self.Equals(other);
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_EqualInternal_True()
|
||||
{
|
||||
@@ -453,9 +440,7 @@ namespace SabreTools.Metadata.DatItems.Test
|
||||
[Fact]
|
||||
public void GetInternalCloneTest()
|
||||
{
|
||||
DatItem<TestDatItemModel> item = new TestDatItem();
|
||||
item.SetName("name");
|
||||
|
||||
DatItem<TestDatItemModel> item = new TestDatItem { Name = "name" };
|
||||
TestDatItemModel actual = item.GetInternalClone();
|
||||
Assert.Equal("name", actual.Name);
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ namespace SabreTools.Metadata.DatItems
|
||||
string key = string.Empty;
|
||||
|
||||
string sourceKeyPadded = source?.Index.ToString().PadLeft(10, '0') + '-';
|
||||
string machineName = machine?.GetName() ?? "Default";
|
||||
string machineName = machine?.Name ?? "Default";
|
||||
|
||||
// Now determine what the key should be based on the bucketedBy value
|
||||
switch (bucketedBy)
|
||||
|
||||
@@ -338,22 +338,6 @@ namespace SabreTools.Metadata.DatItems
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name to use for a Machine
|
||||
/// </summary>
|
||||
/// <returns>Name if available, null otherwise</returns>
|
||||
public string? GetName() => Name;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the name to use for a Machine
|
||||
/// </summary>
|
||||
/// <param name="name">Name to set for the item</param>
|
||||
public void SetName(string? name) => Name = name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning methods
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user