diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-25 13:50:01 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-25 13:50:01 -0400 |
commit | 4d48bdfe7c3806ec1995cd499ca9382ace2d8a53 (patch) | |
tree | 38d7ec99b4fce57426a022be20a7a601bdbe9255 /src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs | |
parent | 2e58f853d27cc200be5b34a1ebef5bbdb7703a49 (diff) | |
download | SMAPI-4d48bdfe7c3806ec1995cd499ca9382ace2d8a53.tar.gz SMAPI-4d48bdfe7c3806ec1995cd499ca9382ace2d8a53.tar.bz2 SMAPI-4d48bdfe7c3806ec1995cd499ca9382ace2d8a53.zip |
drop 'generic' prefix for rewriters since they're all generic now
Diffstat (limited to 'src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs')
-rw-r--r-- | src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs new file mode 100644 index 00000000..516641f2 --- /dev/null +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs @@ -0,0 +1,61 @@ +using Mono.Cecil; +using Mono.Cecil.Cil; +using StardewModdingAPI.AssemblyRewriters.Framework; + +namespace StardewModdingAPI.AssemblyRewriters.Finders +{ + /// <summary>Finds CIL instructions that reference a given field.</summary> + public sealed class FieldFinder : BaseFieldFinder + { + /********* + ** Properties + *********/ + /// <summary>The full type name for which to find references.</summary> + private readonly string FullTypeName; + + /// <summary>The field name for which to find references.</summary> + private readonly string FieldName; + + /// <summary>Whether the field to match is static.</summary> + private readonly bool IsStatic; + + + /********* + ** Accessors + *********/ + /// <summary>A brief noun phrase indicating what the instruction finder matches.</summary> + public override string NounPhrase { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="fullTypeName">The full type name for which to find references.</param> + /// <param name="fieldName">The field name for which to find references.</param> + /// <param name="isStatic">Whether the field to match is static.</param> + public FieldFinder(string fullTypeName, string fieldName, bool isStatic) + { + this.FullTypeName = fullTypeName; + this.FieldName = fieldName; + this.IsStatic = isStatic; + this.NounPhrase = $"obsolete {fullTypeName}.{fieldName} field"; + } + + + /********* + ** Protected methods + *********/ + /// <summary>Get whether a field reference should be rewritten.</summary> + /// <param name="instruction">The IL instruction.</param> + /// <param name="fieldRef">The field reference.</param> + /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param> + protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged) + { + return + this.IsStaticField(instruction) == this.IsStatic + && fieldRef.DeclaringType.FullName == this.FullTypeName + && fieldRef.Name == this.FieldName; + } + } +} |