Make FilterRunner more accurate

This commit is contained in:
Matt Nadareski
2023-08-11 22:14:28 -04:00
parent 5583b35111
commit ee97b7ceea
3 changed files with 13 additions and 4 deletions

View File

@@ -45,14 +45,13 @@ namespace SabreTools.Filter
{
Header => MetadataFile.HeaderKey,
Machine => MetadataFile.MachineKey,
DatItem => dictionaryBase.ReadString(DatItem.TypeKey),
DatItem => TypeHelper.GetXmlRootAttributeElementName(dictionaryBase.GetType()),
_ => null,
};
// Loop through and run each filter in order
foreach (var filter in this.Filters)
{
// TODO: Make this step more accurate
// If the filter isn't for this object type, skip
if (filter.Key[0] != itemName)
continue;

View File

@@ -40,7 +40,18 @@ namespace SabreTools.Filter
return AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(a => a.GetTypes())
.Where(t => t.IsAssignableFrom(typeof(DatItem)) && t.IsClass)
.FirstOrDefault(t => t.GetCustomAttribute<XmlRootAttribute>()?.ElementName == itemType);
.FirstOrDefault(t => GetXmlRootAttributeElementName(t) == itemType);
}
/// <summary>
/// Attempt to get the XmlRootAttribute.ElementName value from a type
/// </summary>
public static string? GetXmlRootAttributeElementName(Type? type)
{
if (type == null)
return null;
return type.GetCustomAttribute<XmlRootAttribute>()?.ElementName;
}
}
}

View File

@@ -3,7 +3,6 @@ namespace SabreTools.Models.Internal
/// <summary>
/// Determine what type of file an item is
/// </summary>
/// <remarks>TODO: Create attribute for internal names</remarks>
public enum ItemType
{
/// <summary>