diff options
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs index a20b8bee..b1fa377a 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs @@ -14,8 +14,8 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters /// <summary>The type whose field to which references should be rewritten.</summary> private readonly Type Type; - /// <summary>The field name to rewrite.</summary> - private readonly string FieldName; + /// <summary>The property name.</summary> + private readonly string PropertyName; /********* @@ -24,13 +24,20 @@ 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> - public FieldToPropertyRewriter(Type type, string fieldName) + /// <param name="propertyName">The property name (if different).</param> + public FieldToPropertyRewriter(Type type, string fieldName, string propertyName) : base(type.FullName, fieldName, InstructionHandleResult.None) { this.Type = type; - this.FieldName = fieldName; + this.PropertyName = propertyName; } + /// <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> + public FieldToPropertyRewriter(Type type, string fieldName) + : this(type, fieldName, fieldName) { } + /// <summary>Perform the predefined logic for an instruction if applicable.</summary> /// <param name="module">The assembly module containing the instruction.</param> /// <param name="cil">The CIL processor.</param> @@ -43,8 +50,9 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters 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}")); + MethodReference propertyRef = module.Import(this.Type.GetMethod($"{methodPrefix}_{this.PropertyName}")); cil.Replace(instruction, cil.Create(OpCodes.Call, propertyRef)); + return InstructionHandleResult.Rewritten; } } |