summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-03-12 18:25:29 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-03-12 18:25:29 -0400
commitccc57935de9b75e17b9f531df87e2ac4dac43dfc (patch)
tree907ba213250089a2833939822950ace659e56fce /src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs
parenta6ed67a9f763b5efab58589776e8eaa31a4f2dbc (diff)
downloadSMAPI-ccc57935de9b75e17b9f531df87e2ac4dac43dfc.tar.gz
SMAPI-ccc57935de9b75e17b9f531df87e2ac4dac43dfc.tar.bz2
SMAPI-ccc57935de9b75e17b9f531df87e2ac4dac43dfc.zip
replace individual instruction finders with generic implementations (#247)
Diffstat (limited to 'src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs')
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs
new file mode 100644
index 00000000..f5443558
--- /dev/null
+++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.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 GenericMethodFinder : 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 GenericMethodFinder(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;
+ }
+ }
+}