mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make FilterRunner more accurate
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user