diff --git a/BurnOutSharp/Matching/MatchUtil.cs b/BurnOutSharp/Matching/MatchUtil.cs index 939c8db2..6936c4aa 100644 --- a/BurnOutSharp/Matching/MatchUtil.cs +++ b/BurnOutSharp/Matching/MatchUtil.cs @@ -130,7 +130,7 @@ namespace BurnOutSharp.Matching /// Enumerable of PathMatchSets to be run on the file /// True if any path match is a success, false if all have to match /// List of strings representing the matched protections, null or empty otherwise - public static List GetAllMatches(List files, IEnumerable matchers, bool any = false) + public static List GetAllMatches(IEnumerable files, IEnumerable matchers, bool any = false) { return FindAllMatches(files, matchers, any, false); } @@ -158,7 +158,7 @@ namespace BurnOutSharp.Matching /// Enumerable of PathMatchSets to be run on the file /// True if any path match is a success, false if all have to match /// String representing the matched protection, null otherwise - public static string GetFirstMatch(List files, IEnumerable matchers, bool any = false) + public static string GetFirstMatch(IEnumerable files, IEnumerable matchers, bool any = false) { var contentMatches = FindAllMatches(files, matchers, any, true); if (contentMatches == null || !contentMatches.Any()) @@ -175,7 +175,7 @@ namespace BurnOutSharp.Matching /// True if any path match is a success, false if all have to match /// True to stop after the first match, false otherwise /// List of strings representing the matched protections, null or empty otherwise - private static List FindAllMatches(List files, IEnumerable matchers, bool any, bool stopAfterFirst) + private static List FindAllMatches(IEnumerable files, IEnumerable matchers, bool any, bool stopAfterFirst) { // If there's no mappings, we can't match if (matchers == null || !matchers.Any()) diff --git a/BurnOutSharp/Matching/PathMatch.cs b/BurnOutSharp/Matching/PathMatch.cs index ff94c771..f44421f3 100644 --- a/BurnOutSharp/Matching/PathMatch.cs +++ b/BurnOutSharp/Matching/PathMatch.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace BurnOutSharp.Matching { @@ -42,10 +43,10 @@ namespace BurnOutSharp.Matching /// /// List of strings to search for the given content /// Tuple of success and matched item - public (bool, string) Match(List stack) + public (bool, string) Match(IEnumerable stack) { // If either array is null or empty, we can't do anything - if (stack == null || stack.Count == 0 || Needle == null || Needle.Length == 0) + if (stack == null || !stack.Any() || Needle == null || Needle.Length == 0) return (false, null); // Preprocess the needle, if necessary diff --git a/BurnOutSharp/Matching/PathMatchSet.cs b/BurnOutSharp/Matching/PathMatchSet.cs index 977cdd23..57c8ae14 100644 --- a/BurnOutSharp/Matching/PathMatchSet.cs +++ b/BurnOutSharp/Matching/PathMatchSet.cs @@ -13,12 +13,12 @@ namespace BurnOutSharp.Matching /// Function to get a path version for this Matcher /// /// - /// A path version method takes the matched path and a list of files + /// A path version method takes the matched path and an enumerable of files /// and returns a single string. That string is either a version string, /// in which case it will be appended to the protection name, or `null`, /// in which case it will cause the protection to be omitted. /// - public Func, string> GetVersion { get; set; } + public Func, string> GetVersion { get; set; } #region Constructors @@ -28,10 +28,10 @@ namespace BurnOutSharp.Matching public PathMatchSet(List needles, string protectionName) : this(needles, null, protectionName) { } - public PathMatchSet(string needle, Func, string> getVersion, string protectionName) + public PathMatchSet(string needle, Func, string> getVersion, string protectionName) : this(new List { needle }, getVersion, protectionName) { } - public PathMatchSet(List needles, Func, string> getVersion, string protectionName) + public PathMatchSet(List needles, Func, string> getVersion, string protectionName) : this(needles.Select(n => new PathMatch(n)).ToList(), getVersion, protectionName) { } public PathMatchSet(PathMatch needle, string protectionName) @@ -40,10 +40,10 @@ namespace BurnOutSharp.Matching public PathMatchSet(List needles, string protectionName) : this(needles, null, protectionName) { } - public PathMatchSet(PathMatch needle, Func, string> getVersion, string protectionName) + public PathMatchSet(PathMatch needle, Func, string> getVersion, string protectionName) : this(new List() { needle }, getVersion, protectionName) { } - public PathMatchSet(List needles, Func, string> getVersion, string protectionName) + public PathMatchSet(List needles, Func, string> getVersion, string protectionName) { Matchers = needles; GetVersion = getVersion; @@ -59,7 +59,7 @@ namespace BurnOutSharp.Matching /// /// List of strings to try to match /// Tuple of passing status and matching values - public (bool, List) MatchesAll(List stack) + public (bool, List) MatchesAll(IEnumerable stack) { // If no path matches are defined, we fail out if (Matchers == null || !Matchers.Any()) @@ -86,7 +86,7 @@ namespace BurnOutSharp.Matching /// /// List of strings to try to match /// Tuple of passing status and first matching value - public (bool, string) MatchesAny(List stack) + public (bool, string) MatchesAny(IEnumerable stack) { // If no path matches are defined, we fail out if (Matchers == null || !Matchers.Any())