From ccc57935de9b75e17b9f531df87e2ac4dac43dfc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 12 Mar 2017 18:25:29 -0400 Subject: replace individual instruction finders with generic implementations (#247) --- .../Finders/GenericMethodFinder.cs | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs (limited to 'src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs') 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 +{ + /// Finds CIL instructions that reference a given method. + public sealed class GenericMethodFinder : BaseMethodFinder + { + /********* + ** Properties + *********/ + /// The full type name for which to find references. + private readonly string FullTypeName; + + /// The method name for which to find references. + private readonly string MethodName; + + + /********* + ** Accessors + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public override string NounPhrase { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The full type name for which to find references. + /// The method name for which to find references. + public GenericMethodFinder(string fullTypeName, string methodName) + { + this.FullTypeName = fullTypeName; + this.MethodName = methodName; + this.NounPhrase = $"obsolete {fullTypeName}.{methodName} method"; + } + + + /********* + ** Protected methods + *********/ + /// Get whether a method reference should be rewritten. + /// The IL instruction. + /// The method reference. + /// Whether the mod was compiled on a different platform. + protected override bool IsMatch(Instruction instruction, MethodReference methodRef, bool platformChanged) + { + return methodRef.DeclaringType.FullName == this.FullTypeName + && methodRef.Name == this.MethodName; + } + } +} -- cgit