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; } } }