summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.AssemblyRewriters/Finders
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-03-25 22:08:48 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-03-25 22:08:48 -0400
commit06f5e92b88fac190f94690f1580775449014e411 (patch)
tree19e9344151d3661ca38d6cda8d5577b64c6dac07 /src/StardewModdingAPI.AssemblyRewriters/Finders
parent7b641d816466fe7d9229374c175f59ee32b8dc5c (diff)
downloadSMAPI-06f5e92b88fac190f94690f1580775449014e411.tar.gz
SMAPI-06f5e92b88fac190f94690f1580775449014e411.tar.bz2
SMAPI-06f5e92b88fac190f94690f1580775449014e411.zip
minor cleanup
Diffstat (limited to 'src/StardewModdingAPI.AssemblyRewriters/Finders')
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs5
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs5
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs25
3 files changed, 19 insertions, 16 deletions
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
/// <summary>Construct an instance.</summary>
/// <param name="fullTypeName">The full type name for which to find references.</param>
/// <param name="eventName">The event name for which to find references.</param>
- public EventFinder(string fullTypeName, string eventName)
+ /// <param name="nounPhrase">A brief noun phrase indicating what the instruction finder matches (or <c>null</c> to generate one).</param>
+ 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
/// <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 MethodFinder(string fullTypeName, string methodName)
+ /// <param name="nounPhrase">A brief noun phrase indicating what the instruction finder matches (or <c>null</c> to generate one).</param>
+ 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
{
/// <summary>Finds CIL instructions that reference a given type.</summary>
- public sealed class TypeFinder : IInstructionFinder
+ public class TypeFinder : IInstructionFinder
{
/*********
** Accessors
@@ -26,10 +26,11 @@ namespace StardewModdingAPI.AssemblyRewriters.Finders
*********/
/// <summary>Construct an instance.</summary>
/// <param name="fullTypeName">The full type name to match.</param>
- public TypeFinder(string fullTypeName)
+ /// <param name="nounPhrase">A brief noun phrase indicating what the instruction finder matches (or <c>null</c> to generate one).</param>
+ public TypeFinder(string fullTypeName, string nounPhrase = null)
{
this.FullTypeName = fullTypeName;
- this.NounPhrase = $"obsolete {fullTypeName} type";
+ this.NounPhrase = nounPhrase ?? $"{fullTypeName} type";
}
/// <summary>Get whether a CIL instruction matches.</summary>
@@ -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;