summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-19 23:42:54 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-19 23:42:54 -0400
commitebf22c1b06cd12ce02df16278062f7d37bc66a4c (patch)
tree06f557d753cefdea530db3f9a01382159c7165fb /src/StardewModdingAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs
parentfd10cf958cb68a41e1aa7ac4d7d2371205be0c75 (diff)
downloadSMAPI-ebf22c1b06cd12ce02df16278062f7d37bc66a4c.tar.gz
SMAPI-ebf22c1b06cd12ce02df16278062f7d37bc66a4c.tar.bz2
SMAPI-ebf22c1b06cd12ce02df16278062f7d37bc66a4c.zip
generalise IInstructionRewriter into IInstructionHandler (#347)
Diffstat (limited to 'src/StardewModdingAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs')
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/StardewModdingAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs b/src/StardewModdingAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs
index 03d1f707..1b005869 100644
--- a/src/StardewModdingAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs
+++ b/src/StardewModdingAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs
@@ -24,32 +24,29 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
/// <summary>Construct an instance.</summary>
/// <param name="type">The type whose field to which references should be rewritten.</param>
/// <param name="fieldName">The field name to rewrite.</param>
- /// <param name="nounPhrase">A brief noun phrase indicating what the instruction finder matches (or <c>null</c> to generate one).</param>
- public FieldToPropertyRewriter(Type type, string fieldName, string nounPhrase = null)
- : base(type.FullName, fieldName, nounPhrase)
+ public FieldToPropertyRewriter(Type type, string fieldName)
+ : base(type.FullName, fieldName, InstructionHandleResult.None)
{
this.Type = type;
this.FieldName = fieldName;
}
- /// <summary>Rewrite a CIL instruction for compatibility.</summary>
- /// <param name="mod">The mod to which the module belongs.</param>
- /// <param name="module">The module being rewritten.</param>
- /// <param name="cil">The CIL rewriter.</param>
- /// <param name="instruction">The instruction to rewrite.</param>
+ /// <summary>Perform the predefined logic for an instruction if applicable.</summary>
+ /// <param name="mod">The mod containing the instruction.</param>
+ /// <param name="module">The assembly module containing the instruction.</param>
+ /// <param name="cil">The CIL processor.</param>
+ /// <param name="instruction">The instruction to handle.</param>
/// <param name="assemblyMap">Metadata for mapping assemblies to the current platform.</param>
/// <param name="platformChanged">Whether the mod was compiled on a different platform.</param>
- /// <returns>Returns whether the instruction was rewritten.</returns>
- /// <exception cref="IncompatibleInstructionException">The CIL instruction is not compatible, and can't be rewritten.</exception>
- public override bool Rewrite(IModMetadata mod, ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
+ public override InstructionHandleResult Handle(IModMetadata mod, ModuleDefinition module, ILProcessor cil, Instruction instruction, PlatformAssemblyMap assemblyMap, bool platformChanged)
{
if (!this.IsMatch(instruction))
- return false;
+ return InstructionHandleResult.None;
string methodPrefix = instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Ldfld ? "get" : "set";
MethodReference propertyRef = module.Import(this.Type.GetMethod($"{methodPrefix}_{this.FieldName}"));
cil.Replace(instruction, cil.Create(OpCodes.Call, propertyRef));
- return true;
+ return InstructionHandleResult.Rewritten;
}
}
}