diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-25 15:17:26 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-25 15:17:26 -0400 |
commit | 7b641d816466fe7d9229374c175f59ee32b8dc5c (patch) | |
tree | 6ed0c1036071b1eba0ca181a2c9257fbfeeedde8 /src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs | |
parent | 267e2469da290cbdb93bd58cea0272de403bbdab (diff) | |
download | SMAPI-7b641d816466fe7d9229374c175f59ee32b8dc5c.tar.gz SMAPI-7b641d816466fe7d9229374c175f59ee32b8dc5c.tar.bz2 SMAPI-7b641d816466fe7d9229374c175f59ee32b8dc5c.zip |
simplify CIL rewriter hierarchy
Diffstat (limited to 'src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs')
-rw-r--r-- | src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs deleted file mode 100644 index bb71a9d7..00000000 --- a/src/StardewModdingAPI.AssemblyRewriters/Framework/BaseMethodFinder.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using Mono.Cecil; -using Mono.Cecil.Cil; - -namespace StardewModdingAPI.AssemblyRewriters.Framework -{ - /// <summary>Base class for a method finder.</summary> - public abstract class BaseMethodFinder : IInstructionFinder - { - /********* - ** Accessors - *********/ - /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary> - public abstract string NounPhrase { get; } - - - /********* - ** Public methods - *********/ - /// <summary>Get whether a CIL instruction matches.</summary> - /// <param name="instruction">The IL instruction.</param> - /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param> - public bool IsMatch(Instruction instruction, bool platformChanged) - { - if (instruction.OpCode != OpCodes.Call && instruction.OpCode != OpCodes.Callvirt) - return false; // not a method reference - return this.IsMatch(instruction, (MethodReference)instruction.Operand, platformChanged); - } - - - /********* - ** 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 abstract bool IsMatch(Instruction instruction, MethodReference methodRef, bool platformChanged); - - /// <summary>Get whether a method definition matches the signature expected by a method reference.</summary> - /// <param name="definition">The method definition.</param> - /// <param name="reference">The method reference.</param> - protected bool HasMatchingSignature(MethodInfo definition, MethodReference reference) - { - // same name - if (definition.Name != reference.Name) - return false; - - // same arguments - ParameterInfo[] definitionParameters = definition.GetParameters(); - ParameterDefinition[] referenceParameters = reference.Parameters.ToArray(); - if (referenceParameters.Length != definitionParameters.Length) - return false; - for (int i = 0; i < referenceParameters.Length; i++) - { - if (!RewriteHelper.IsMatchingType(definitionParameters[i].ParameterType, referenceParameters[i].ParameterType)) - return false; - } - return true; - } - - /// <summary>Get whether a type has a method whose signature matches the one expected by a method reference.</summary> - /// <param name="type">The type to check.</param> - /// <param name="reference">The method reference.</param> - protected bool HasMatchingSignature(Type type, MethodReference reference) - { - return type - .GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public) - .Any(method => this.HasMatchingSignature(method, reference)); - } - } -} |