From 06f5e92b88fac190f94690f1580775449014e411 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 25 Mar 2017 22:08:48 -0400 Subject: minor cleanup --- .../Finders/EventFinder.cs | 5 +++-- .../Finders/MethodFinder.cs | 5 +++-- .../Finders/TypeFinder.cs | 25 +++++++++++----------- 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'src/StardewModdingAPI.AssemblyRewriters/Finders') diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs index 9d0184c6..848e54ff 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs @@ -29,11 +29,12 @@ namespace StardewModdingAPI.AssemblyRewriters.Finders /// Construct an instance. /// The full type name for which to find references. /// The event name for which to find references. - public EventFinder(string fullTypeName, string eventName) + /// A brief noun phrase indicating what the instruction finder matches (or null to generate one). + public EventFinder(string fullTypeName, string eventName, string nounPhrase = null) { this.FullTypeName = fullTypeName; this.EventName = eventName; - this.NounPhrase = $"obsolete {fullTypeName}.{eventName} event"; + this.NounPhrase = nounPhrase ?? $"{fullTypeName}.{eventName} event"; } diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs index bea549ee..d174bacd 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs @@ -29,11 +29,12 @@ namespace StardewModdingAPI.AssemblyRewriters.Finders /// Construct an instance. /// The full type name for which to find references. /// The method name for which to find references. - public MethodFinder(string fullTypeName, string methodName) + /// A brief noun phrase indicating what the instruction finder matches (or null to generate one). + public MethodFinder(string fullTypeName, string methodName, string nounPhrase = null) { this.FullTypeName = fullTypeName; this.MethodName = methodName; - this.NounPhrase = $"obsolete {fullTypeName}.{methodName} method"; + this.NounPhrase = nounPhrase ?? $"{fullTypeName}.{methodName} method"; } diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs index ba8e7102..8f492d5f 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs @@ -5,7 +5,7 @@ using Mono.Cecil.Cil; namespace StardewModdingAPI.AssemblyRewriters.Finders { /// Finds CIL instructions that reference a given type. - public sealed class TypeFinder : IInstructionFinder + public class TypeFinder : IInstructionFinder { /********* ** Accessors @@ -26,10 +26,11 @@ namespace StardewModdingAPI.AssemblyRewriters.Finders *********/ /// Construct an instance. /// The full type name to match. - public TypeFinder(string fullTypeName) + /// A brief noun phrase indicating what the instruction finder matches (or null to generate one). + public TypeFinder(string fullTypeName, string nounPhrase = null) { this.FullTypeName = fullTypeName; - this.NounPhrase = $"obsolete {fullTypeName} type"; + this.NounPhrase = nounPhrase ?? $"{fullTypeName} type"; } /// Get whether a CIL instruction matches. @@ -40,22 +41,22 @@ namespace StardewModdingAPI.AssemblyRewriters.Finders string fullName = this.FullTypeName; // field reference - if (instruction.OpCode == OpCodes.Ldfld || instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Stfld || instruction.OpCode == OpCodes.Stsfld) + FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); + if (fieldRef != null) { - FieldReference field = (FieldReference)instruction.Operand; return - field.DeclaringType.FullName == fullName // field on target class - || field.FieldType.FullName == fullName; // field value is target class + fieldRef.DeclaringType.FullName == fullName // field on target class + || fieldRef.FieldType.FullName == fullName; // field value is target class } // method reference - if (instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt) + MethodReference methodRef = RewriteHelper.AsMethodReference(instruction); + if (methodRef != null) { - MethodReference method = (MethodReference)instruction.Operand; return - method.DeclaringType.FullName == fullName // method on target class - || method.ReturnType.FullName == fullName // method returns target class - || method.Parameters.Any(p => p.ParameterType.FullName == fullName); // method parameters + methodRef.DeclaringType.FullName == fullName // method on target class + || methodRef.ReturnType.FullName == fullName // method returns target class + || methodRef.Parameters.Any(p => p.ParameterType.FullName == fullName); // method parameters } return false; -- cgit