diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-11-27 12:08:00 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-11-27 12:08:00 -0500 |
commit | 8917fb6697b5eae0c14bcf2437aef7e9a8d51abb (patch) | |
tree | c869aec8f23c8177103d6495854addef35d8485d /src/StardewModdingAPI/Framework/AssemblyRewriting | |
parent | 2e40ad7ad3d83970969b160eae87fc9aa4608916 (diff) | |
download | SMAPI-8917fb6697b5eae0c14bcf2437aef7e9a8d51abb.tar.gz SMAPI-8917fb6697b5eae0c14bcf2437aef7e9a8d51abb.tar.bz2 SMAPI-8917fb6697b5eae0c14bcf2437aef7e9a8d51abb.zip |
only rewrite assemblies if needed (#166)
Diffstat (limited to 'src/StardewModdingAPI/Framework/AssemblyRewriting')
-rw-r--r-- | src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs | 21 |
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); + } } } |