mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Add machine type analogue filtering again
This commit is contained in:
@@ -335,6 +335,14 @@ namespace SabreTools.Metadata.Filter
|
||||
/// </summary>
|
||||
private static bool ParseMachineFilterId(ref string itemName, ref string fieldName)
|
||||
{
|
||||
// Special case for machine type
|
||||
if (string.Equals(fieldName, "type", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
itemName = "machine";
|
||||
fieldName = "type";
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the set of properties
|
||||
var properties = GetProperties(typeof(Machine));
|
||||
if (properties is null)
|
||||
|
||||
@@ -77,6 +77,21 @@ namespace SabreTools.Metadata.Filter
|
||||
/// </summary>
|
||||
private bool MatchesEqual(object obj)
|
||||
{
|
||||
// Special case for machine type
|
||||
if (obj is Machine machine
|
||||
&& string.Equals(Key.ItemName, "machine", StringComparison.OrdinalIgnoreCase)
|
||||
&& string.Equals(Key.FieldName, "type", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Value?.ToLowerInvariant() switch
|
||||
{
|
||||
"none" => machine.IsBios != true && machine.IsDevice != true && machine.IsMechanical != true,
|
||||
"bios" => machine.IsBios == true,
|
||||
"device" or "dev" => machine.IsDevice == true,
|
||||
"mechanical" or "mech" => machine.IsMechanical == true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
// Process the check value
|
||||
if (!GetCheckValue(obj, Key.FieldName, out string? checkValue))
|
||||
return string.IsNullOrEmpty(Value);
|
||||
@@ -119,6 +134,21 @@ namespace SabreTools.Metadata.Filter
|
||||
/// </summary>
|
||||
private bool MatchesNotEqual(object obj)
|
||||
{
|
||||
// Special case for machine type
|
||||
if (obj is Machine machine
|
||||
&& string.Equals(Key.ItemName, "machine", StringComparison.OrdinalIgnoreCase)
|
||||
&& string.Equals(Key.FieldName, "type", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Value?.ToLowerInvariant() switch
|
||||
{
|
||||
"none" => machine.IsBios == true || machine.IsDevice == true || machine.IsMechanical == true,
|
||||
"bios" => machine.IsBios != true,
|
||||
"device" or "dev" => machine.IsDevice != true,
|
||||
"mechanical" or "mech" => machine.IsMechanical != true,
|
||||
_ => true,
|
||||
};
|
||||
}
|
||||
|
||||
// Process the check value
|
||||
if (!GetCheckValue(obj, Key.FieldName, out string? checkValue))
|
||||
return string.IsNullOrEmpty(Value);
|
||||
|
||||
@@ -76,14 +76,6 @@ namespace SabreTools.Metadata.Filter
|
||||
// Get the key as a string
|
||||
string key = filter.Key.ToString();
|
||||
|
||||
// Special case for machine types
|
||||
if (filter.Key.ItemName == "machine" && filter.Key.FieldName == "isbios")
|
||||
key = $"{"machine"}.COMBINEDTYPE";
|
||||
else if (filter.Key.ItemName == "machine" && filter.Key.FieldName == "isdevice")
|
||||
key = $"{"machine"}.COMBINEDTYPE";
|
||||
else if (filter.Key.ItemName == "machine" && filter.Key.FieldName == "ismechanical")
|
||||
key = $"{"machine"}.COMBINEDTYPE";
|
||||
|
||||
// Set the expected group type
|
||||
GroupType groupType = GroupType.OR;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user