diff --git a/SabreTools.Data.Extensions/MetadataExtensions.cs b/SabreTools.Data.Extensions/MetadataExtensions.cs index 3cce03d3..a1329fcd 100644 --- a/SabreTools.Data.Extensions/MetadataExtensions.cs +++ b/SabreTools.Data.Extensions/MetadataExtensions.cs @@ -10,140 +10,6 @@ namespace SabreTools.Data.Extensions // TODO: Combine yes/partial/no enums public static class MetadataExtensions { - #region Cloning - - /// - /// Deep clone a DictionaryBase object - /// - /// TODO: Move this to Clone methods in each file when keys go away entirely - public static DictionaryBase? DeepClone(this DictionaryBase self) - { - // Handle types that are cloneable - if (self is Adjuster adjuster) - return adjuster.Clone() as Adjuster; - else if (self is Analog analog) - return analog.Clone() as Analog; - else if (self is Archive archive) - return archive.Clone() as Archive; - else if (self is BiosSet biosSet) - return biosSet.Clone() as BiosSet; - else if (self is Blank blank) - return blank.Clone() as Blank; - else if (self is Chip chip) - return chip.Clone() as Chip; - else if (self is Condition condition) - return condition.Clone() as Condition; - else if (self is Configuration configuration) - return configuration.Clone() as Configuration; - else if (self is ConfLocation confLocation) - return confLocation.Clone() as ConfLocation; - else if (self is ConfSetting confSetting) - return confSetting.Clone() as ConfSetting; - else if (self is Control control) - return control.Clone() as Control; - else if (self is DataArea dataArea) - return dataArea.Clone() as DataArea; - else if (self is Device device) - return device.Clone() as Device; - else if (self is DeviceRef deviceRef) - return deviceRef.Clone() as DeviceRef; - else if (self is DipLocation dipLocation) - return dipLocation.Clone() as DipLocation; - else if (self is DipSwitch dipSwitch) - return dipSwitch.Clone() as DipSwitch; - else if (self is DipValue dipValue) - return dipValue.Clone() as DipValue; - else if (self is Disk disk) - return disk.Clone() as Disk; - else if (self is DiskArea diskArea) - return diskArea.Clone() as DiskArea; - else if (self is Display display) - return display.Clone() as Display; - else if (self is Driver driver) - return driver.Clone() as Driver; - else if (self is Dump dump) - return dump.Clone() as Dump; - else if (self is Extension extension) - return extension.Clone() as Extension; - else if (self is Feature feature) - return feature.Clone() as Feature; - else if (self is Header header) - return header.Clone() as Header; - else if (self is Info info) - return info.Clone() as Info; - else if (self is Input input) - return input.Clone() as Input; - else if (self is Instance instance) - return instance.Clone() as Instance; - else if (self is Machine machine) - return machine.Clone() as Machine; - else if (self is Media media) - return media.Clone() as Media; - else if (self is Original original) - return original.Clone() as Original; - else if (self is Part part) - return part.Clone() as Part; - else if (self is Port port) - return port.Clone() as Port; - else if (self is RamOption ramOption) - return ramOption.Clone() as RamOption; - else if (self is Release release) - return release.Clone() as Release; - else if (self is ReleaseDetails releaseDetails) - return releaseDetails.Clone() as ReleaseDetails; - else if (self is Rom rom) - return rom.Clone() as Rom; - else if (self is Sample sample) - return sample.Clone() as Sample; - else if (self is Serials serials) - return serials.Clone() as Serials; - else if (self is SharedFeat sharedFeat) - return sharedFeat.Clone() as SharedFeat; - else if (self is Slot slot) - return slot.Clone() as Slot; - else if (self is SlotOption slotOption) - return slotOption.Clone() as SlotOption; - else if (self is SoftwareList softwareList) - return softwareList.Clone() as SoftwareList; - else if (self is Sound sound) - return sound.Clone() as Sound; - else if (self is SourceDetails sourceDetails) - return sourceDetails.Clone() as SourceDetails; - else if (self is Video video) - return video.Clone() as Video; - - // If construction failed, we can't do anything - if (Activator.CreateInstance(self.GetType()) is not DictionaryBase clone) - return null; - - // Loop through and clone per type - foreach (string key in self.Keys) - { - object? value = self[key]; - clone[key] = value switch - { - // Primative types - bool or long or double or string => value, - - // DictionaryBase types - DictionaryBase db => db.DeepClone(), - - // Enumerable types - byte[] bytArr => bytArr.Clone(), - string[] strArr => strArr.Clone(), - DictionaryBase[] dbArr => Array.ConvertAll(dbArr, DeepClone), - ICloneable[] clArr => Array.ConvertAll(clArr, cl => cl.Clone()), - - // Everything else just copies - _ => value, - }; - } - - return clone; - } - - #endregion - #region Conversion ///