Filter tree is reflection-free

This commit is contained in:
Matt Nadareski
2026-04-07 11:17:57 -04:00
parent 76c5dc40e3
commit 94658ae225
3 changed files with 180 additions and 1 deletions

View File

@@ -1982,5 +1982,122 @@ namespace SabreTools.Metadata.Filter.Test
}
#endregion
#region Sound
[Theory]
[InlineData("sound.channels", "12345")]
public void Matches_Sound(string itemField, string value)
{
var filter = new FilterObject(itemField, value, Operation.Equals);
Sound obj = new Sound
{
Channels = 12345,
};
bool actual = filter.Matches(obj);
Assert.True(actual);
}
#endregion
#region SourceDetails
[Theory]
[InlineData("sourcedetails.appendtonumber", "appendtonumber")]
[InlineData("sourcedetails.comment1", "comment1")]
[InlineData("sourcedetails.comment2", "comment2")]
[InlineData("sourcedetails.dumpdate", "dumpdate")]
[InlineData("sourcedetails.dumpdateinfo", "1")]
[InlineData("sourcedetails.dumper", "dumper")]
[InlineData("sourcedetails.id", "id")]
[InlineData("sourcedetails.link1", "link1")]
[InlineData("sourcedetails.link1public", "1")]
[InlineData("sourcedetails.link2", "link2")]
[InlineData("sourcedetails.link2public", "1")]
[InlineData("sourcedetails.link3", "link3")]
[InlineData("sourcedetails.link3public", "1")]
[InlineData("sourcedetails.mediatitle", "mediatitle")]
[InlineData("sourcedetails.nodump", "1")]
[InlineData("sourcedetails.origin", "origin")]
[InlineData("sourcedetails.originalformat", "originalformat")]
[InlineData("sourcedetails.project", "project")]
[InlineData("sourcedetails.region", "region")]
[InlineData("sourcedetails.releasedate", "releasedate")]
[InlineData("sourcedetails.releasedateinfo", "1")]
[InlineData("sourcedetails.rominfo", "rominfo")]
[InlineData("sourcedetails.section", "section")]
[InlineData("sourcedetails.tool", "tool")]
public void Matches_SourceDetails(string itemField, string value)
{
var filter = new FilterObject(itemField, value, Operation.Equals);
SourceDetails obj = new SourceDetails
{
AppendToNumber = "appendtonumber",
Comment1 = "comment1",
Comment2 = "comment2",
DumpDate = "dumpdate",
DumpDateInfo = true,
Dumper = "dumper",
Id = "id",
Link1 = "link1",
Link1Public = true,
Link2 = "link2",
Link2Public = true,
Link3 = "link3",
Link3Public = true,
MediaTitle = "mediatitle",
Nodump = true,
Origin = "origin",
OriginalFormat = "originalformat",
Project = "project",
Region = "region",
ReleaseDate = "releasedate",
ReleaseDateInfo = true,
RomInfo = "rominfo",
Section = "section",
Tool = "tool",
};
bool actual = filter.Matches(obj);
Assert.True(actual);
}
#endregion
#region Video
[Theory]
[InlineData("video.aspectx", "12345")]
[InlineData("video.aspecty", "12345")]
[InlineData("video.height", "12345")]
[InlineData("video.y", "12345")]
[InlineData("video.orientation", "horizontal")]
[InlineData("video.rotate", "horizontal")]
[InlineData("video.refresh", "123.45")]
[InlineData("video.freq", "123.45")]
[InlineData("video.displaytype", "vector")]
[InlineData("video.screen", "vector")]
[InlineData("video.width", "12345")]
[InlineData("video.x", "12345")]
public void Matches_Video(string itemField, string value)
{
var filter = new FilterObject(itemField, value, Operation.Equals);
Video obj = new Video
{
AspectX = 12345,
AspectY = 12345,
Height = 12345,
Orientation = Rotation.East,
Refresh = 123.45,
Screen = DisplayType.Vector,
Width = 12345,
};
bool actual = filter.Matches(obj);
Assert.True(actual);
}
#endregion
}
}

View File

@@ -771,6 +771,64 @@ namespace SabreTools.Metadata.Filter
"tag",
];
/// <summary>
/// Known keys for Sound
/// </summary>
private static readonly string[] _soundKeys =
[
"channels",
];
/// <summary>
/// Known keys for SourceDetails
/// </summary>
private static readonly string[] _sourceDetailsKeys =
[
"appendtonumber",
"comment1",
"comment2",
"dumpdate",
"dumpdateinfo",
"dumper",
"id",
"link1",
"link1public",
"link2",
"link2public",
"link3",
"link3public",
"mediatitle",
"nodump",
"origin",
"originalformat",
"project",
"region",
"releasedate",
"releasedateinfo",
"rominfo",
"section",
"tool",
];
/// <summary>
/// Known keys for Video
/// </summary>
private static readonly string[] _videoKeys =
[
"aspectx",
"aspecty",
"displaytype",
"freq",
"height",
"orientation",
"refresh",
"rotate",
"screen",
"width",
"x",
"y",
];
#endregion
/// <summary>
@@ -988,6 +1046,9 @@ namespace SabreTools.Metadata.Filter
"slot" => _slotKeys,
"slotoption" => _slotOptionKeys,
"softwarelist" => _softwareListKeys,
"sound" => _soundKeys,
"sourcedetails" => _sourceDetailsKeys,
"video" => _videoKeys,
_ => null,
};
if (properties is null)

View File

@@ -2426,12 +2426,13 @@ namespace SabreTools.Metadata.Filter
return true;
case "orientation":
case "rotate":
checkValue = obj.Orientation?.AsStringValue();
checkValue = obj.Orientation?.AsStringValue(useSecond: true);
return true;
case "refresh":
case "freq":
checkValue = obj.Refresh?.ToString();
return true;
case "displaytype":
case "screen":
checkValue = obj.Screen?.AsStringValue();
return true;