diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-24 23:04:23 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-24 23:04:23 -0400 |
commit | 08b37c70a35edd413e0da0c408e77d255200cf63 (patch) | |
tree | 3a6c3014ab21435d32c7f65931521212e7d65666 /src/SMAPI/Framework/ModLoading/Finders | |
parent | 85efb3112912a28dbdc82b18d0be8dd117f8c8ee (diff) | |
download | SMAPI-08b37c70a35edd413e0da0c408e77d255200cf63.tar.gz SMAPI-08b37c70a35edd413e0da0c408e77d255200cf63.tar.bz2 SMAPI-08b37c70a35edd413e0da0c408e77d255200cf63.zip |
move type match lambda up into TypeFinder (#532)
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Finders')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs b/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs index 45349def..79045241 100644 --- a/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs +++ b/src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using Mono.Cecil; using Mono.Cecil.Cil; @@ -16,6 +17,9 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders /// <summary>The result to return for matching instructions.</summary> private readonly InstructionHandleResult Result; + /// <summary>A lambda which overrides a matched type.</summary> + protected readonly Func<TypeReference, bool> ShouldIgnore; + /********* ** Accessors @@ -30,11 +34,13 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders /// <summary>Construct an instance.</summary> /// <param name="fullTypeName">The full type name to match.</param> /// <param name="result">The result to return for matching instructions.</param> - public TypeFinder(string fullTypeName, InstructionHandleResult result) + /// <param name="shouldIgnore">A lambda which overrides a matched type.</param> + public TypeFinder(string fullTypeName, InstructionHandleResult result, Func<TypeReference, bool> shouldIgnore = null) { this.FullTypeName = fullTypeName; this.Result = result; this.NounPhrase = $"{fullTypeName} type"; + this.ShouldIgnore = shouldIgnore ?? (p => false); } /// <summary>Perform the predefined logic for a method if applicable.</summary> @@ -113,7 +119,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Finders protected bool IsMatch(TypeReference type) { // root type - if (type.FullName == this.FullTypeName) + if (type.FullName == this.FullTypeName && !this.ShouldIgnore(type)) return true; // generic arguments |