From 7fc49203f490d177e79f8913eb73694bbcc0be6d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 30 Sep 2020 13:25:40 -0700 Subject: [PATCH] Sub items should not check types --- SabreTools.Library/DatFiles/DatFile.cs | 5 ++- SabreTools.Library/DatFiles/Listxml.cs | 26 +++++++------- SabreTools.Library/DatFiles/SoftwareList.cs | 6 ++-- SabreTools.Library/DatItems/Adjuster.cs | 8 ++--- SabreTools.Library/DatItems/Analog.cs | 21 ++++++++++-- SabreTools.Library/DatItems/Condition.cs | 8 ++--- SabreTools.Library/DatItems/Configuration.cs | 28 +++++++-------- SabreTools.Library/DatItems/Control.cs | 21 ++++++++++-- SabreTools.Library/DatItems/DataArea.cs | 21 ++++++++++-- SabreTools.Library/DatItems/Device.cs | 20 +++++------ SabreTools.Library/DatItems/DipSwitch.cs | 36 ++++++++++---------- SabreTools.Library/DatItems/Disk.cs | 12 +++---- SabreTools.Library/DatItems/DiskArea.cs | 21 ++++++++++-- SabreTools.Library/DatItems/Extension.cs | 21 ++++++++++-- SabreTools.Library/DatItems/Input.cs | 10 +++--- SabreTools.Library/DatItems/Instance.cs | 21 ++++++++++-- SabreTools.Library/DatItems/Location.cs | 21 ++++++++++-- SabreTools.Library/DatItems/Part.cs | 31 ++++++++++++----- SabreTools.Library/DatItems/PartFeature.cs | 21 ++++++++++-- SabreTools.Library/DatItems/Port.cs | 10 +++--- SabreTools.Library/DatItems/Rom.cs | 12 +++---- SabreTools.Library/DatItems/Setting.cs | 29 ++++++++++++---- SabreTools.Library/DatItems/Slot.cs | 10 +++--- SabreTools.Library/DatItems/SlotOption.cs | 21 ++++++++++-- 24 files changed, 302 insertions(+), 138 deletions(-) diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index f325c3b4..19f43d18 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -1409,7 +1409,7 @@ namespace SabreTools.Library.DatFiles List slotOptions = Items[machine] .Where(i => i.ItemType == ItemType.Slot) .Select(i => i as Slot) - .Where(s => s.SlotOptions != null && s.SlotOptions.Count != 0) + .Where(s => s.SlotOptionsSpecified) .SelectMany(s => s.SlotOptions) .Select(so => so.DeviceName) .Distinct() @@ -1473,8 +1473,7 @@ namespace SabreTools.Library.DatFiles List slotItems = Items[slotOption]; newSlotOptions.AddRange(slotItems .Where(i => i.ItemType == ItemType.Slot) - .Where(s => (s as Slot).SlotOptions != null) - .Where(s => (s as Slot).SlotOptions.Count != 0) + .Where(s => (s as Slot).SlotOptionsSpecified) .SelectMany(s => (s as Slot).SlotOptions) .Select(o => o.DeviceName)); diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs index 1d41dfcf..f837cb45 100644 --- a/SabreTools.Library/DatFiles/Listxml.cs +++ b/SabreTools.Library/DatFiles/Listxml.cs @@ -1330,7 +1330,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteStartElement("adjuster"); xtw.WriteRequiredAttributeString("name", adjuster.Name); xtw.WriteOptionalAttributeString("default", adjuster.Default.FromYesNo()); - if (adjuster.Conditions != null) + if (adjuster.ConditionsSpecified) { foreach (var adjusterCondition in adjuster.Conditions) { @@ -1381,7 +1381,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteOptionalAttributeString("tag", configuration.Tag); xtw.WriteOptionalAttributeString("mask", configuration.Mask); - if (configuration.Conditions != null) + if (configuration.ConditionsSpecified) { foreach (var configurationCondition in configuration.Conditions) { @@ -1393,7 +1393,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); } } - if (configuration.Locations != null) + if (configuration.LocationsSpecified) { foreach (var location in configuration.Locations) { @@ -1404,7 +1404,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); } } - if (configuration.Settings != null) + if (configuration.SettingsSpecified) { foreach (var setting in configuration.Settings) { @@ -1426,7 +1426,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteOptionalAttributeString("fixed_image", device.FixedImage); xtw.WriteOptionalAttributeString("mandatory", device.Mandatory?.ToString()); xtw.WriteOptionalAttributeString("interface", device.Interface); - if (device.Instances != null) + if (device.InstancesSpecified) { foreach (var instance in device.Instances) { @@ -1436,7 +1436,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); } } - if (device.Extensions != null) + if (device.ExtensionsSpecified) { foreach (var extension in device.Extensions) { @@ -1461,7 +1461,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteOptionalAttributeString("name", dipSwitch.Name); xtw.WriteOptionalAttributeString("tag", dipSwitch.Tag); xtw.WriteOptionalAttributeString("mask", dipSwitch.Mask); - if (dipSwitch.Conditions != null) + if (dipSwitch.ConditionsSpecified) { foreach (var dipSwitchCondition in dipSwitch.Conditions) { @@ -1473,7 +1473,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); } } - if (dipSwitch.Locations != null) + if (dipSwitch.LocationsSpecified) { foreach (var location in dipSwitch.Locations) { @@ -1484,7 +1484,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); } } - if (dipSwitch.Values != null) + if (dipSwitch.ValuesSpecified) { foreach (var value in dipSwitch.Values) { @@ -1492,7 +1492,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteOptionalAttributeString("name", value.Name); xtw.WriteOptionalAttributeString("value", value.Value); xtw.WriteOptionalAttributeString("default", value.Default.FromYesNo()); - if (value.Conditions != null) + if (value.ConditionsSpecified) { foreach (var dipValueCondition in value.Conditions) { @@ -1570,7 +1570,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteOptionalAttributeString("tilt", input.Tilt.FromYesNo()); xtw.WriteOptionalAttributeString("players", input.Players?.ToString()); xtw.WriteOptionalAttributeString("coins", input.Coins?.ToString()); - if (input.Controls != null) + if (input.ControlsSpecified) { foreach (var control in input.Controls) { @@ -1597,7 +1597,7 @@ namespace SabreTools.Library.DatFiles var port = datItem as Port; xtw.WriteStartElement("port"); xtw.WriteOptionalAttributeString("tag", port.Tag); - if (port.Analogs != null) + if (port.AnalogsSpecified) { foreach (var analog in port.Analogs) { @@ -1645,7 +1645,7 @@ namespace SabreTools.Library.DatFiles var slot = datItem as Slot; xtw.WriteStartElement("slot"); xtw.WriteOptionalAttributeString("name", slot.Name); - if (slot.SlotOptions != null) + if (slot.SlotOptionsSpecified) { foreach (var slotOption in slot.SlotOptions) { diff --git a/SabreTools.Library/DatFiles/SoftwareList.cs b/SabreTools.Library/DatFiles/SoftwareList.cs index 21395075..1b465821 100644 --- a/SabreTools.Library/DatFiles/SoftwareList.cs +++ b/SabreTools.Library/DatFiles/SoftwareList.cs @@ -677,7 +677,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteRequiredAttributeString("name", dipSwitch.Name); xtw.WriteRequiredAttributeString("tag", dipSwitch.Tag); xtw.WriteRequiredAttributeString("mask", dipSwitch.Mask); - if (dipSwitch.Values != null) + if (dipSwitch.ValuesSpecified) { foreach (Setting dipValue in dipSwitch.Values) { @@ -701,7 +701,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteRequiredAttributeString("name", disk.Part?.Name); xtw.WriteRequiredAttributeString("interface", disk.Part?.Interface); - if (disk.Part?.Features != null && disk.Part?.Features.Count > 0) + if (disk.Part?.FeaturesSpecified == true) { foreach (PartFeature partFeature in disk.Part.Features) { @@ -748,7 +748,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteRequiredAttributeString("name", rom.Part?.Name); xtw.WriteRequiredAttributeString("interface", rom.Part?.Interface); - if (rom.Part?.Features != null && rom.Part?.Features.Count > 0) + if (rom.Part?.FeaturesSpecified == true) { foreach (PartFeature kvp in rom.Part.Features) { diff --git a/SabreTools.Library/DatItems/Adjuster.cs b/SabreTools.Library/DatItems/Adjuster.cs index 0560ce57..764176fc 100644 --- a/SabreTools.Library/DatItems/Adjuster.cs +++ b/SabreTools.Library/DatItems/Adjuster.cs @@ -74,7 +74,7 @@ namespace SabreTools.Library.DatItems Default = mappings[Field.DatItem_Default].AsYesNo(); // Field.DatItem_Conditions does not apply here - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -136,7 +136,7 @@ namespace SabreTools.Library.DatItems return match; // If the conditions match - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -198,7 +198,7 @@ namespace SabreTools.Library.DatItems return false; // Filter on individual conditions - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -226,7 +226,7 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Default)) Default = null; - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { diff --git a/SabreTools.Library/DatItems/Analog.cs b/SabreTools.Library/DatItems/Analog.cs index 51378a89..fcc9571e 100644 --- a/SabreTools.Library/DatItems/Analog.cs +++ b/SabreTools.Library/DatItems/Analog.cs @@ -99,9 +99,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on mask if (!filter.PassStringFilter(filter.DatItem_Analog_Mask, Mask)) diff --git a/SabreTools.Library/DatItems/Condition.cs b/SabreTools.Library/DatItems/Condition.cs index 1c7eef64..0b4c825e 100644 --- a/SabreTools.Library/DatItems/Condition.cs +++ b/SabreTools.Library/DatItems/Condition.cs @@ -179,10 +179,6 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public bool PassesFilter(Filter filter, bool sub) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; - if (sub) { // Filter on tag @@ -205,6 +201,10 @@ namespace SabreTools.Library.DatItems } else { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + // Filter on tag if (!filter.PassStringFilter(filter.DatItem_Tag, Tag)) return false; diff --git a/SabreTools.Library/DatItems/Configuration.cs b/SabreTools.Library/DatItems/Configuration.cs index b86bae96..5e2d51c3 100644 --- a/SabreTools.Library/DatItems/Configuration.cs +++ b/SabreTools.Library/DatItems/Configuration.cs @@ -100,7 +100,7 @@ namespace SabreTools.Library.DatItems if (mappings.Keys.Contains(Field.DatItem_Mask)) Mask = mappings[Field.DatItem_Mask]; - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -108,7 +108,7 @@ namespace SabreTools.Library.DatItems } } - if (Locations != null) + if (LocationsSpecified) { foreach (Location location in Locations) { @@ -116,7 +116,7 @@ namespace SabreTools.Library.DatItems } } - if (Settings != null) + if (SettingsSpecified) { foreach (Setting setting in Settings) { @@ -183,7 +183,7 @@ namespace SabreTools.Library.DatItems return match; // If the conditions match - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -192,7 +192,7 @@ namespace SabreTools.Library.DatItems } // If the locations match - if (Locations != null) + if (LocationsSpecified) { foreach (Location location in Locations) { @@ -201,7 +201,7 @@ namespace SabreTools.Library.DatItems } // If the settings match - if (Settings != null) + if (SettingsSpecified) { foreach (Setting setting in Settings) { @@ -267,7 +267,7 @@ namespace SabreTools.Library.DatItems return false; // Filter on individual conditions - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -277,21 +277,21 @@ namespace SabreTools.Library.DatItems } // Filter on individual locations - if (Locations != null) + if (LocationsSpecified) { foreach (Location location in Locations) { - if (!location.PassesFilter(filter)) + if (!location.PassesFilter(filter, true)) return false; } } // Filter on individual conditions - if (Settings != null) + if (SettingsSpecified) { foreach (Setting setting in Settings) { - if (!setting.PassesFilter(filter)) + if (!setting.PassesFilter(filter, true)) return false; } } @@ -318,7 +318,7 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Mask)) Mask = null; - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -326,7 +326,7 @@ namespace SabreTools.Library.DatItems } } - if (Locations != null) + if (LocationsSpecified) { foreach (Location location in Locations) { @@ -334,7 +334,7 @@ namespace SabreTools.Library.DatItems } } - if (Settings != null) + if (SettingsSpecified) { foreach (Setting setting in Settings) { diff --git a/SabreTools.Library/DatItems/Control.cs b/SabreTools.Library/DatItems/Control.cs index 5a50888c..6e264732 100644 --- a/SabreTools.Library/DatItems/Control.cs +++ b/SabreTools.Library/DatItems/Control.cs @@ -262,9 +262,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on control type if (filter.DatItem_Control_Type.MatchesPositive(ControlType.NULL, ControlType) == false) diff --git a/SabreTools.Library/DatItems/DataArea.cs b/SabreTools.Library/DatItems/DataArea.cs index c1c72027..a7e7c484 100644 --- a/SabreTools.Library/DatItems/DataArea.cs +++ b/SabreTools.Library/DatItems/DataArea.cs @@ -185,9 +185,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on area name if (!filter.PassStringFilter(filter.DatItem_AreaName, Name)) diff --git a/SabreTools.Library/DatItems/Device.cs b/SabreTools.Library/DatItems/Device.cs index 4f99c707..c95f7b54 100644 --- a/SabreTools.Library/DatItems/Device.cs +++ b/SabreTools.Library/DatItems/Device.cs @@ -109,7 +109,7 @@ namespace SabreTools.Library.DatItems if (mappings.Keys.Contains(Field.DatItem_Interface)) Interface = mappings[Field.DatItem_Interface]; - if (Instances != null) + if (InstancesSpecified) { foreach (Instance instance in Instances) { @@ -117,7 +117,7 @@ namespace SabreTools.Library.DatItems } } - if (Extensions != null) + if (ExtensionsSpecified) { foreach (Extension extension in Extensions) { @@ -186,7 +186,7 @@ namespace SabreTools.Library.DatItems return match; // If the instances match - if (Instances != null) + if (InstancesSpecified) { foreach (Instance instance in Instances) { @@ -195,7 +195,7 @@ namespace SabreTools.Library.DatItems } // If the extensions match - if (Extensions != null) + if (ExtensionsSpecified) { foreach (Extension extension in Extensions) { @@ -244,21 +244,21 @@ namespace SabreTools.Library.DatItems return false; // Filter on individual instances - if (Instances != null) + if (InstancesSpecified) { foreach (Instance instance in Instances) { - if (!instance.PassesFilter(filter)) + if (!instance.PassesFilter(filter, true)) return false; } } // Filter on individual extensions - if (Extensions != null) + if (ExtensionsSpecified) { foreach (Extension extension in Extensions) { - if (!extension.PassesFilter(filter)) + if (!extension.PassesFilter(filter, true)) return false; } } @@ -291,7 +291,7 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Interface)) Interface = null; - if (Instances != null) + if (InstancesSpecified) { foreach (Instance instance in Instances) { @@ -299,7 +299,7 @@ namespace SabreTools.Library.DatItems } } - if (Extensions != null) + if (ExtensionsSpecified) { foreach (Extension extension in Extensions) { diff --git a/SabreTools.Library/DatItems/DipSwitch.cs b/SabreTools.Library/DatItems/DipSwitch.cs index 9f56f6fd..d1f08552 100644 --- a/SabreTools.Library/DatItems/DipSwitch.cs +++ b/SabreTools.Library/DatItems/DipSwitch.cs @@ -129,7 +129,7 @@ namespace SabreTools.Library.DatItems if (mappings.Keys.Contains(Field.DatItem_Mask)) Mask = mappings[Field.DatItem_Mask]; - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -137,7 +137,7 @@ namespace SabreTools.Library.DatItems } } - if (Locations != null) + if (LocationsSpecified) { foreach (Location location in Locations) { @@ -145,7 +145,7 @@ namespace SabreTools.Library.DatItems } } - if (Values != null) + if (ValuesSpecified) { foreach (Setting value in Values) { @@ -226,11 +226,11 @@ namespace SabreTools.Library.DatItems return match; // If the part matches - if (Part != null) + if (PartSpecified) match &= (Part == newOther.Part); // If the conditions match - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -239,7 +239,7 @@ namespace SabreTools.Library.DatItems } // If the locations match - if (Locations != null) + if (LocationsSpecified) { foreach (Location location in Locations) { @@ -248,7 +248,7 @@ namespace SabreTools.Library.DatItems } // If the values match - if (Values != null) + if (ValuesSpecified) { foreach (Setting value in Values) { @@ -316,7 +316,7 @@ namespace SabreTools.Library.DatItems return false; // Filter on individual conditions - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -326,21 +326,21 @@ namespace SabreTools.Library.DatItems } // Filter on individual locations - if (Locations != null) + if (LocationsSpecified) { foreach (Location location in Locations) { - if (!location.PassesFilter(filter)) + if (!location.PassesFilter(filter, true)) return false; } } // Filter on individual conditions - if (Values != null) + if (ValuesSpecified) { foreach (Setting value in Values) { - if (!value.PassesFilter(filter)) + if (!value.PassesFilter(filter, true)) return false; } } @@ -352,7 +352,7 @@ namespace SabreTools.Library.DatItems // Filter on Part if (PartSpecified) { - if (!Part.PassesFilter(filter)) + if (!Part.PassesFilter(filter, true)) return false; } @@ -383,7 +383,7 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Mask)) Mask = null; - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -391,7 +391,7 @@ namespace SabreTools.Library.DatItems } } - if (Locations != null) + if (LocationsSpecified) { foreach (Location location in Locations) { @@ -399,7 +399,7 @@ namespace SabreTools.Library.DatItems } } - if (Values != null) + if (ValuesSpecified) { foreach (Setting value in Values) { @@ -411,7 +411,7 @@ namespace SabreTools.Library.DatItems #region SoftwareList - if (Part != null) + if (PartSpecified) Part.RemoveFields(fields); #endregion @@ -477,7 +477,7 @@ namespace SabreTools.Library.DatItems #region SoftwareList - if (Part != null && newItem.Part != null) + if (PartSpecified && newItem.PartSpecified) Part.ReplaceFields(newItem.Part, fields); #endregion diff --git a/SabreTools.Library/DatItems/Disk.cs b/SabreTools.Library/DatItems/Disk.cs index bbcd8ef6..24298748 100644 --- a/SabreTools.Library/DatItems/Disk.cs +++ b/SabreTools.Library/DatItems/Disk.cs @@ -493,14 +493,14 @@ namespace SabreTools.Library.DatItems // Filter on DiskArea if (DiskAreaSpecified) { - if (!DiskArea.PassesFilter(filter)) + if (!DiskArea.PassesFilter(filter, true)) return false; } // Filter on Part if (PartSpecified) { - if (!Part.PassesFilter(filter)) + if (!Part.PassesFilter(filter, true)) return false; } @@ -553,10 +553,10 @@ namespace SabreTools.Library.DatItems #region SoftwareList - if (DiskArea != null) + if (DiskAreaSpecified) DiskArea.RemoveFields(fields); - if (Part != null) + if (PartSpecified) Part.RemoveFields(fields); #endregion @@ -669,10 +669,10 @@ namespace SabreTools.Library.DatItems #region SoftwareList - if (DiskArea != null && newItem.DiskArea != null) + if (DiskAreaSpecified && newItem.DiskAreaSpecified) DiskArea.ReplaceFields(newItem.DiskArea, fields); - if (Part != null && newItem.Part != null) + if (PartSpecified && newItem.PartSpecified) Part.ReplaceFields(newItem.Part, fields); #endregion diff --git a/SabreTools.Library/DatItems/DiskArea.cs b/SabreTools.Library/DatItems/DiskArea.cs index 7c7817a7..88425f02 100644 --- a/SabreTools.Library/DatItems/DiskArea.cs +++ b/SabreTools.Library/DatItems/DiskArea.cs @@ -140,9 +140,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on area name if (!filter.PassStringFilter(filter.DatItem_AreaName, Name)) diff --git a/SabreTools.Library/DatItems/Extension.cs b/SabreTools.Library/DatItems/Extension.cs index 5c9825cc..e3585593 100644 --- a/SabreTools.Library/DatItems/Extension.cs +++ b/SabreTools.Library/DatItems/Extension.cs @@ -138,9 +138,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on item name if (!filter.PassStringFilter(filter.DatItem_Extension_Name, Name)) diff --git a/SabreTools.Library/DatItems/Input.cs b/SabreTools.Library/DatItems/Input.cs index 735ac9ec..5b28c30e 100644 --- a/SabreTools.Library/DatItems/Input.cs +++ b/SabreTools.Library/DatItems/Input.cs @@ -93,7 +93,7 @@ namespace SabreTools.Library.DatItems if (mappings.Keys.Contains(Field.DatItem_Coins)) Coins = Sanitizer.CleanLong(mappings[Field.DatItem_Coins]); - if (Controls != null) + if (ControlsSpecified) { foreach (Control control in Controls) { @@ -159,7 +159,7 @@ namespace SabreTools.Library.DatItems return match; // If the controls match - if (Controls != null) + if (ControlsSpecified) { foreach (Control control in Controls) { @@ -202,11 +202,11 @@ namespace SabreTools.Library.DatItems return false; // Filter on individual controls - if (Controls != null) + if (ControlsSpecified) { foreach (Control control in Controls) { - if (!control.PassesFilter(filter)) + if (!control.PassesFilter(filter, true)) return false; } } @@ -236,7 +236,7 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Coins)) Coins = null; - if (Controls != null) + if (ControlsSpecified) { foreach (Control control in Controls) { diff --git a/SabreTools.Library/DatItems/Instance.cs b/SabreTools.Library/DatItems/Instance.cs index 09c75cd7..abe14c03 100644 --- a/SabreTools.Library/DatItems/Instance.cs +++ b/SabreTools.Library/DatItems/Instance.cs @@ -149,9 +149,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on item name if (!filter.PassStringFilter(filter.DatItem_Instance_Name, Name)) diff --git a/SabreTools.Library/DatItems/Location.cs b/SabreTools.Library/DatItems/Location.cs index 0d393e3e..4d6eefb1 100644 --- a/SabreTools.Library/DatItems/Location.cs +++ b/SabreTools.Library/DatItems/Location.cs @@ -168,9 +168,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on item name if (!filter.PassStringFilter(filter.DatItem_Location_Name, Name)) diff --git a/SabreTools.Library/DatItems/Part.cs b/SabreTools.Library/DatItems/Part.cs index c201db61..396e40c9 100644 --- a/SabreTools.Library/DatItems/Part.cs +++ b/SabreTools.Library/DatItems/Part.cs @@ -64,7 +64,7 @@ namespace SabreTools.Library.DatItems Interface = mappings[Field.DatItem_Part_Interface]; // Handle Feature-specific fields - if (Features != null) + if (FeaturesSpecified) { foreach (PartFeature partFeature in Features) { @@ -127,7 +127,7 @@ namespace SabreTools.Library.DatItems return match; // If the features match - if (Features != null) + if (FeaturesSpecified) { foreach (PartFeature partFeature in Features) { @@ -176,9 +176,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on part name if (!filter.PassStringFilter(filter.DatItem_Part_Name, Name)) @@ -189,11 +204,11 @@ namespace SabreTools.Library.DatItems return false; // Filter on features - if (Features != null) + if (FeaturesSpecified) { foreach (PartFeature partFeature in Features) { - if (!partFeature.PassesFilter(filter)) + if (!partFeature.PassesFilter(filter, true)) return false; } } @@ -217,7 +232,7 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Part_Interface)) Interface = null; - if (Features != null) + if (FeaturesSpecified) { foreach (PartFeature partFeature in Features) { diff --git a/SabreTools.Library/DatItems/PartFeature.cs b/SabreTools.Library/DatItems/PartFeature.cs index 1a36207d..68424179 100644 --- a/SabreTools.Library/DatItems/PartFeature.cs +++ b/SabreTools.Library/DatItems/PartFeature.cs @@ -149,9 +149,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on name if (!filter.PassStringFilter(filter.DatItem_Part_Feature_Name, Name)) diff --git a/SabreTools.Library/DatItems/Port.cs b/SabreTools.Library/DatItems/Port.cs index 0209881a..f51daaf3 100644 --- a/SabreTools.Library/DatItems/Port.cs +++ b/SabreTools.Library/DatItems/Port.cs @@ -49,7 +49,7 @@ namespace SabreTools.Library.DatItems if (mappings.Keys.Contains(Field.DatItem_Tag)) Tag = mappings[Field.DatItem_Tag]; - if (Analogs != null) + if (AnalogsSpecified) { foreach (Analog analog in Analogs) { @@ -109,7 +109,7 @@ namespace SabreTools.Library.DatItems return match; // If the analogs match - if (Analogs != null) + if (AnalogsSpecified) { foreach (Analog analog in Analogs) { @@ -140,11 +140,11 @@ namespace SabreTools.Library.DatItems return false; // Filter on individual analogs - if (Analogs != null) + if (AnalogsSpecified) { foreach (Analog analog in Analogs) { - if (!analog.PassesFilter(filter)) + if (!analog.PassesFilter(filter, true)) return false; } } @@ -165,7 +165,7 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Tag)) Tag = null; - if (Analogs != null) + if (AnalogsSpecified) { foreach (Analog analog in Analogs) { diff --git a/SabreTools.Library/DatItems/Rom.cs b/SabreTools.Library/DatItems/Rom.cs index 72363b34..9ac85e36 100644 --- a/SabreTools.Library/DatItems/Rom.cs +++ b/SabreTools.Library/DatItems/Rom.cs @@ -943,14 +943,14 @@ namespace SabreTools.Library.DatItems // Filter on DataArea if (DataAreaSpecified) { - if (!DataArea.PassesFilter(filter)) + if (!DataArea.PassesFilter(filter, true)) return false; } // Filter on Part if (PartSpecified) { - if (!Part.PassesFilter(filter)) + if (!Part.PassesFilter(filter, true)) return false; } @@ -1067,10 +1067,10 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Value)) Value = null; - if (DataArea != null) + if (DataAreaSpecified) DataArea.RemoveFields(fields); - if (Part != null) + if (PartSpecified) Part.RemoveFields(fields); #endregion @@ -1291,10 +1291,10 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Value)) Value = newItem.Value; - if (DataArea != null && newItem.DataArea != null) + if (DataAreaSpecified && newItem.DataAreaSpecified) DataArea.ReplaceFields(newItem.DataArea, fields); - if (Part != null && newItem.Part != null) + if (PartSpecified && newItem.PartSpecified) Part.ReplaceFields(newItem.Part, fields); #endregion diff --git a/SabreTools.Library/DatItems/Setting.cs b/SabreTools.Library/DatItems/Setting.cs index f3b097de..8b440ecf 100644 --- a/SabreTools.Library/DatItems/Setting.cs +++ b/SabreTools.Library/DatItems/Setting.cs @@ -83,7 +83,7 @@ namespace SabreTools.Library.DatItems if (mappings.Keys.Contains(Field.DatItem_Setting_Default)) Default = mappings[Field.DatItem_Setting_Default].AsYesNo(); - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -148,7 +148,7 @@ namespace SabreTools.Library.DatItems return match; // If the conditions match - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -197,9 +197,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on item name if (!filter.PassStringFilter(filter.DatItem_Setting_Name, Name)) @@ -214,7 +229,7 @@ namespace SabreTools.Library.DatItems return false; // Filter on individual conditions - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { @@ -245,7 +260,7 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Setting_Default)) Default = null; - if (Conditions != null) + if (ConditionsSpecified) { foreach (Condition condition in Conditions) { diff --git a/SabreTools.Library/DatItems/Slot.cs b/SabreTools.Library/DatItems/Slot.cs index 0b7130ba..4a9a9c17 100644 --- a/SabreTools.Library/DatItems/Slot.cs +++ b/SabreTools.Library/DatItems/Slot.cs @@ -60,7 +60,7 @@ namespace SabreTools.Library.DatItems if (mappings.Keys.Contains(Field.DatItem_Name)) Name = mappings[Field.DatItem_Name]; - if (SlotOptions != null) + if (SlotOptionsSpecified) { foreach (SlotOption slotOption in SlotOptions) { @@ -121,7 +121,7 @@ namespace SabreTools.Library.DatItems return match; // If the slot options match - if (SlotOptions != null) + if (SlotOptionsSpecified) { foreach (SlotOption slotOption in SlotOptions) { @@ -179,11 +179,11 @@ namespace SabreTools.Library.DatItems return false; // Filter on individual slot options - if (SlotOptions != null) + if (SlotOptionsSpecified) { foreach (SlotOption slotOption in SlotOptions) { - if (!slotOption.PassesFilter(filter)) + if (!slotOption.PassesFilter(filter, true)) return false; } } @@ -204,7 +204,7 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.DatItem_Name)) Name = null; - if (SlotOptions != null) + if (SlotOptionsSpecified) { foreach (SlotOption slotOption in SlotOptions) { diff --git a/SabreTools.Library/DatItems/SlotOption.cs b/SabreTools.Library/DatItems/SlotOption.cs index 06192621..ffc19c3d 100644 --- a/SabreTools.Library/DatItems/SlotOption.cs +++ b/SabreTools.Library/DatItems/SlotOption.cs @@ -165,9 +165,24 @@ namespace SabreTools.Library.DatItems /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { - // Check common fields first - if (!base.PassesFilter(filter)) - return false; + return PassesFilter(filter, false); + } + + /// + /// Check to see if a DatItem passes the filter + /// + /// Filter to check against + /// True if this is a subitem, false otherwise + /// True if the item passed the filter, false otherwise + public bool PassesFilter(Filter filter, bool sub) + { + // If we're a top-level item, check common fields + if (!sub) + { + // Check common fields first + if (!base.PassesFilter(filter)) + return false; + } // Filter on item name if (!filter.PassStringFilter(filter.DatItem_SlotOption_Name, Name))