diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-03-13 20:25:06 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-03-13 20:25:06 -0400 |
commit | afb3c49bbaab07f3148f70d54f5140cdd83f8c20 (patch) | |
tree | dd60902c878c38617f97644b912afb38c568755e /src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs | |
parent | 833d98f49136325edfc4463097710cf2391dd5b2 (diff) | |
parent | 76445dc3589265ba259070300120e96a17957e50 (diff) | |
download | SMAPI-afb3c49bbaab07f3148f70d54f5140cdd83f8c20.tar.gz SMAPI-afb3c49bbaab07f3148f70d54f5140cdd83f8c20.tar.bz2 SMAPI-afb3c49bbaab07f3148f70d54f5140cdd83f8c20.zip |
Merge branch 'develop' into stable
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; } } |