From afb9ab3e4e966a6ab1c9db06341a8dcbb3185e1e Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 5 Nov 2024 20:10:33 -0500 Subject: [PATCH] Define delegates instead of anonymous funcs --- .../Content/ContentMatchSet.cs | 20 ++++++------ SabreTools.Matching/Delegates.cs | 32 +++++++++++++++++++ SabreTools.Matching/Paths/PathMatchSet.cs | 11 +++---- 3 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 SabreTools.Matching/Delegates.cs diff --git a/SabreTools.Matching/Content/ContentMatchSet.cs b/SabreTools.Matching/Content/ContentMatchSet.cs index c44f69a..d3c339f 100644 --- a/SabreTools.Matching/Content/ContentMatchSet.cs +++ b/SabreTools.Matching/Content/ContentMatchSet.cs @@ -19,7 +19,7 @@ namespace SabreTools.Matching.Content /// to the match name, or `null`, in which case it will cause /// the match name to be omitted. /// - public Func, string?>? GetArrayVersion { get; } + public GetArrayVersion? GetArrayVersion { get; } /// /// Function to get a content version @@ -31,7 +31,7 @@ namespace SabreTools.Matching.Content /// to the match name, or `null`, in which case it will cause /// the match name to be omitted. /// - public Func, string?>? GetStreamVersion { get; } + public GetStreamVersion? GetStreamVersion { get; } #region Generic Constructors @@ -51,16 +51,16 @@ namespace SabreTools.Matching.Content #region Array Constructors - public ContentMatchSet(byte?[] needle, Func, string?>? getArrayVersion, string matchName) + public ContentMatchSet(byte?[] needle, GetArrayVersion? getArrayVersion, string matchName) : this([needle], getArrayVersion, matchName) { } - public ContentMatchSet(List needles, Func, string?>? getArrayVersion, string matchName) + public ContentMatchSet(List needles, GetArrayVersion? getArrayVersion, string matchName) : this(needles.ConvertAll(n => new ContentMatch(n)), getArrayVersion, matchName) { } - public ContentMatchSet(ContentMatch needle, Func, string?>? getArrayVersion, string matchName) + public ContentMatchSet(ContentMatch needle, GetArrayVersion? getArrayVersion, string matchName) : this([needle], getArrayVersion, matchName) { } - public ContentMatchSet(List needles, Func, string?>? getArrayVersion, string matchName) + public ContentMatchSet(List needles, GetArrayVersion? getArrayVersion, string matchName) { Matchers = needles; GetArrayVersion = getArrayVersion; @@ -71,16 +71,16 @@ namespace SabreTools.Matching.Content #region Stream Constructors - public ContentMatchSet(byte?[] needle, Func, string?>? getStreamVersion, string matchName) + public ContentMatchSet(byte?[] needle, GetStreamVersion? getStreamVersion, string matchName) : this([needle], getStreamVersion, matchName) { } - public ContentMatchSet(List needles, Func, string?>? getStreamVersion, string matchName) + public ContentMatchSet(List needles, GetStreamVersion? getStreamVersion, string matchName) : this(needles.ConvertAll(n => new ContentMatch(n)), getStreamVersion, matchName) { } - public ContentMatchSet(ContentMatch needle, Func, string?>? getStreamVersion, string matchName) + public ContentMatchSet(ContentMatch needle, GetStreamVersion? getStreamVersion, string matchName) : this([needle], getStreamVersion, matchName) { } - public ContentMatchSet(List needles, Func, string?>? getStreamVersion, string matchName) + public ContentMatchSet(List needles, GetStreamVersion? getStreamVersion, string matchName) { Matchers = needles; GetStreamVersion = getStreamVersion; diff --git a/SabreTools.Matching/Delegates.cs b/SabreTools.Matching/Delegates.cs new file mode 100644 index 0000000..943d4fd --- /dev/null +++ b/SabreTools.Matching/Delegates.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.IO; + +namespace SabreTools.Matching +{ + /// + /// Get a version number from a file + /// + /// File path to get the version from + /// Optional file contents as a byte array + /// List of positions in the array that were matched + /// Version string on success, null on failure + public delegate string? GetArrayVersion(string path, byte[]? content, List positions); + + /// + /// Get a version number from an input path + /// + /// File or directory path to get the version from + /// Optional set of files in the directory + /// Version string on success, null on failure + public delegate string? GetPathVersion(string path, IEnumerable? files); + + /// + /// Get a version number from a file + /// + /// File path to get the version from + /// Optional file contents as a Stream + /// List of positions in the Stream that were matched + /// Version string on success, null on failure + public delegate string? GetStreamVersion(string path, Stream? content, List positions); +} \ No newline at end of file diff --git a/SabreTools.Matching/Paths/PathMatchSet.cs b/SabreTools.Matching/Paths/PathMatchSet.cs index 793cbc4..79f120a 100644 --- a/SabreTools.Matching/Paths/PathMatchSet.cs +++ b/SabreTools.Matching/Paths/PathMatchSet.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; namespace SabreTools.Matching.Paths @@ -17,7 +16,7 @@ namespace SabreTools.Matching.Paths /// in which case it will be appended to the match name, or `null`, /// in which case it will cause the match name to be omitted. /// - public Func?, string?>? GetVersion { get; } + public GetPathVersion? GetVersion { get; } #region Constructors @@ -27,10 +26,10 @@ namespace SabreTools.Matching.Paths public PathMatchSet(List needles, string matchName) : this(needles, null, matchName) { } - public PathMatchSet(string needle, Func?, string?>? getVersion, string matchName) + public PathMatchSet(string needle, GetPathVersion? getVersion, string matchName) : this([needle], getVersion, matchName) { } - public PathMatchSet(List needles, Func?, string?>? getVersion, string matchName) + public PathMatchSet(List needles, GetPathVersion? getVersion, string matchName) : this(needles.ConvertAll(n => new PathMatch(n)), getVersion, matchName) { } public PathMatchSet(PathMatch needle, string matchName) @@ -39,10 +38,10 @@ namespace SabreTools.Matching.Paths public PathMatchSet(List needles, string matchName) : this(needles, null, matchName) { } - public PathMatchSet(PathMatch needle, Func?, string?>? getVersion, string matchName) + public PathMatchSet(PathMatch needle, GetPathVersion? getVersion, string matchName) : this([needle], getVersion, matchName) { } - public PathMatchSet(List needles, Func?, string?>? getVersion, string matchName) + public PathMatchSet(List needles, GetPathVersion? getVersion, string matchName) { Matchers = needles; GetVersion = getVersion;