summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-03-25 13:50:01 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-03-25 13:50:01 -0400
commit4d48bdfe7c3806ec1995cd499ca9382ace2d8a53 (patch)
tree38d7ec99b4fce57426a022be20a7a601bdbe9255 /src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs
parent2e58f853d27cc200be5b34a1ebef5bbdb7703a49 (diff)
downloadSMAPI-4d48bdfe7c3806ec1995cd499ca9382ace2d8a53.tar.gz
SMAPI-4d48bdfe7c3806ec1995cd499ca9382ace2d8a53.tar.bz2
SMAPI-4d48bdfe7c3806ec1995cd499ca9382ace2d8a53.zip
drop 'generic' prefix for rewriters since they're all generic now
Diffstat (limited to 'src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs')
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs
new file mode 100644
index 00000000..6c210d68
--- /dev/null
+++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs
@@ -0,0 +1,54 @@
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using StardewModdingAPI.AssemblyRewriters.Framework;
+
+namespace StardewModdingAPI.AssemblyRewriters.Finders
+{
+ /// <summary>Finds CIL instructions that reference a given method.</summary>
+ public sealed class MethodFinder : BaseMethodFinder
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The full type name for which to find references.</summary>
+ private readonly string FullTypeName;
+
+ /// <summary>The method name for which to find references.</summary>
+ private readonly string MethodName;
+
+
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary>
+ public override string NounPhrase { get; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="fullTypeName">The full type name for which to find references.</param>
+ /// <param name="methodName">The method name for which to find references.</param>
+ public MethodFinder(string fullTypeName, string methodName)
+ {
+ this.FullTypeName = fullTypeName;
+ this.MethodName = methodName;
+ this.NounPhrase = $"obsolete {fullTypeName}.{methodName} method";
+ }
+
+
+ /*********
+ ** Protected methods
+ *********/
+ /// <summary>Get whether a method reference should be rewritten.</summary>
+ /// <param name="instruction">The IL instruction.</param>
+ /// <param name="methodRef">The method reference.</param>
+ /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
+ protected override bool IsMatch(Instruction instruction, MethodReference methodRef, bool platformChanged)
+ {
+ return methodRef.DeclaringType.FullName == this.FullTypeName
+ && methodRef.Name == this.MethodName;
+ }
+ }
+}