summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/AssemblyRewriting
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework/AssemblyRewriting')
-rw-r--r--src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs b/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs
index 7a339266..2bfb43e4 100644
--- a/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs
+++ b/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs
@@ -65,24 +65,29 @@ namespace StardewModdingAPI.Framework.AssemblyRewriting
foreach (ModuleDefinition module in assembly.Modules)
{
// remove old assembly references
+ bool shouldRewrite = false;
for (int i = 0; i < module.AssemblyReferences.Count; i++)
{
- bool shouldRemove = this.RemoveAssemblyNames.Any(name => module.AssemblyReferences[i].Name == name) || this.TargetAssemblies.Any(a => module.AssemblyReferences[i].Name == a.GetName().Name);
+ bool shouldRemove = this.RemoveAssemblyNames.Any(name => module.AssemblyReferences[i].Name == name);
if (shouldRemove)
{
+ shouldRewrite = true;
module.AssemblyReferences.RemoveAt(i);
i--;
}
}
- // add target assembly references
- foreach (AssemblyNameReference target in this.AssemblyNameReferences.Values)
- module.AssemblyReferences.Add(target);
+ // replace references
+ if (shouldRewrite)
+ {
+ // add target assembly references
+ foreach (AssemblyNameReference target in this.AssemblyNameReferences.Values)
+ module.AssemblyReferences.Add(target);
- // rewrite type scopes to use target assemblies
- TypeReference[] refs = (TypeReference[])module.GetTypeReferences();
- foreach (TypeReference type in refs)
- this.ChangeTypeScope(type);
+ // rewrite type scopes to use target assemblies
+ foreach (TypeReference type in module.GetTypeReferences())
+ this.ChangeTypeScope(type);
+ }
}
}