mirror of
https://github.com/SabreTools/SabreTools.Matching.git
synced 2026-07-08 18:06:06 +00:00
Define delegates instead of anonymous funcs
This commit is contained in:
@@ -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.
|
||||
/// </remarks>
|
||||
public Func<string, byte[]?, List<int>, string?>? GetArrayVersion { get; }
|
||||
public GetArrayVersion? GetArrayVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
public Func<string, Stream?, List<int>, 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, byte[]?, List<int>, string?>? getArrayVersion, string matchName)
|
||||
public ContentMatchSet(byte?[] needle, GetArrayVersion? getArrayVersion, string matchName)
|
||||
: this([needle], getArrayVersion, matchName) { }
|
||||
|
||||
public ContentMatchSet(List<byte?[]> needles, Func<string, byte[]?, List<int>, string?>? getArrayVersion, string matchName)
|
||||
public ContentMatchSet(List<byte?[]> needles, GetArrayVersion? getArrayVersion, string matchName)
|
||||
: this(needles.ConvertAll(n => new ContentMatch(n)), getArrayVersion, matchName) { }
|
||||
|
||||
public ContentMatchSet(ContentMatch needle, Func<string, byte[]?, List<int>, string?>? getArrayVersion, string matchName)
|
||||
public ContentMatchSet(ContentMatch needle, GetArrayVersion? getArrayVersion, string matchName)
|
||||
: this([needle], getArrayVersion, matchName) { }
|
||||
|
||||
public ContentMatchSet(List<ContentMatch> needles, Func<string, byte[]?, List<int>, string?>? getArrayVersion, string matchName)
|
||||
public ContentMatchSet(List<ContentMatch> 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, Stream?, List<int>, string?>? getStreamVersion, string matchName)
|
||||
public ContentMatchSet(byte?[] needle, GetStreamVersion? getStreamVersion, string matchName)
|
||||
: this([needle], getStreamVersion, matchName) { }
|
||||
|
||||
public ContentMatchSet(List<byte?[]> needles, Func<string, Stream?, List<int>, string?>? getStreamVersion, string matchName)
|
||||
public ContentMatchSet(List<byte?[]> needles, GetStreamVersion? getStreamVersion, string matchName)
|
||||
: this(needles.ConvertAll(n => new ContentMatch(n)), getStreamVersion, matchName) { }
|
||||
|
||||
public ContentMatchSet(ContentMatch needle, Func<string, Stream?, List<int>, string?>? getStreamVersion, string matchName)
|
||||
public ContentMatchSet(ContentMatch needle, GetStreamVersion? getStreamVersion, string matchName)
|
||||
: this([needle], getStreamVersion, matchName) { }
|
||||
|
||||
public ContentMatchSet(List<ContentMatch> needles, Func<string, Stream?, List<int>, string?>? getStreamVersion, string matchName)
|
||||
public ContentMatchSet(List<ContentMatch> needles, GetStreamVersion? getStreamVersion, string matchName)
|
||||
{
|
||||
Matchers = needles;
|
||||
GetStreamVersion = getStreamVersion;
|
||||
|
||||
32
SabreTools.Matching/Delegates.cs
Normal file
32
SabreTools.Matching/Delegates.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace SabreTools.Matching
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a version number from a file
|
||||
/// </summary>
|
||||
/// <param name="path">File path to get the version from</param>
|
||||
/// <param name="content">Optional file contents as a byte array</param>
|
||||
/// <param name="positions">List of positions in the array that were matched</param>
|
||||
/// <returns>Version string on success, null on failure</returns>
|
||||
public delegate string? GetArrayVersion(string path, byte[]? content, List<int> positions);
|
||||
|
||||
/// <summary>
|
||||
/// Get a version number from an input path
|
||||
/// </summary>
|
||||
/// <param name="path">File or directory path to get the version from</param>
|
||||
/// <param name="files">Optional set of files in the directory</param>
|
||||
/// <returns>Version string on success, null on failure</returns>
|
||||
public delegate string? GetPathVersion(string path, IEnumerable<string>? files);
|
||||
|
||||
/// <summary>
|
||||
/// Get a version number from a file
|
||||
/// </summary>
|
||||
/// <param name="path">File path to get the version from</param>
|
||||
/// <param name="content">Optional file contents as a Stream</param>
|
||||
/// <param name="positions">List of positions in the Stream that were matched</param>
|
||||
/// <returns>Version string on success, null on failure</returns>
|
||||
public delegate string? GetStreamVersion(string path, Stream? content, List<int> positions);
|
||||
}
|
||||
@@ -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.
|
||||
/// </remarks>
|
||||
public Func<string, IEnumerable<string>?, string?>? GetVersion { get; }
|
||||
public GetPathVersion? GetVersion { get; }
|
||||
|
||||
#region Constructors
|
||||
|
||||
@@ -27,10 +26,10 @@ namespace SabreTools.Matching.Paths
|
||||
public PathMatchSet(List<string> needles, string matchName)
|
||||
: this(needles, null, matchName) { }
|
||||
|
||||
public PathMatchSet(string needle, Func<string, IEnumerable<string>?, string?>? getVersion, string matchName)
|
||||
public PathMatchSet(string needle, GetPathVersion? getVersion, string matchName)
|
||||
: this([needle], getVersion, matchName) { }
|
||||
|
||||
public PathMatchSet(List<string> needles, Func<string, IEnumerable<string>?, string?>? getVersion, string matchName)
|
||||
public PathMatchSet(List<string> 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<PathMatch> needles, string matchName)
|
||||
: this(needles, null, matchName) { }
|
||||
|
||||
public PathMatchSet(PathMatch needle, Func<string, IEnumerable<string>?, string?>? getVersion, string matchName)
|
||||
public PathMatchSet(PathMatch needle, GetPathVersion? getVersion, string matchName)
|
||||
: this([needle], getVersion, matchName) { }
|
||||
|
||||
public PathMatchSet(List<PathMatch> needles, Func<string, IEnumerable<string>?, string?>? getVersion, string matchName)
|
||||
public PathMatchSet(List<PathMatch> needles, GetPathVersion? getVersion, string matchName)
|
||||
{
|
||||
Matchers = needles;
|
||||
GetVersion = getVersion;
|
||||
|
||||
Reference in New Issue
Block a user