summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/AssemblyRewriting
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2016-11-27 15:56:47 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2016-11-27 15:56:47 -0500
commitf7b8879011873fa8f7a3d5dd7db27254bfc90469 (patch)
tree7c4e42901614ede42621fd4265c89e131eea4f19 /src/StardewModdingAPI/Framework/AssemblyRewriting
parent0d94c628bbc1d1ab098e0a90ee5758ee69694887 (diff)
downloadSMAPI-f7b8879011873fa8f7a3d5dd7db27254bfc90469.tar.gz
SMAPI-f7b8879011873fa8f7a3d5dd7db27254bfc90469.tar.bz2
SMAPI-f7b8879011873fa8f7a3d5dd7db27254bfc90469.zip
supplement assembly resolution for Mono (#166)
Diffstat (limited to 'src/StardewModdingAPI/Framework/AssemblyRewriting')
-rw-r--r--src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs21
-rw-r--r--src/StardewModdingAPI/Framework/AssemblyRewriting/PlatformAssemblyMap.cs35
2 files changed, 43 insertions, 13 deletions
diff --git a/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs b/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs
index 7081df15..66c36c03 100644
--- a/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs
+++ b/src/StardewModdingAPI/Framework/AssemblyRewriting/AssemblyTypeRewriter.cs
@@ -11,11 +11,8 @@ namespace StardewModdingAPI.Framework.AssemblyRewriting
/*********
** Properties
*********/
- /// <summary>The assemblies to target. Equivalent types will be rewritten to use these assemblies.</summary>
- private readonly Assembly[] TargetAssemblies;
-
- /// <summary>>The short assembly names to remove as assembly reference, and replace with the <see cref="TargetAssemblies"/>.</summary>
- private readonly string[] RemoveAssemblyNames;
+ /// <summary>Metadata for mapping assemblies to the current <see cref="Platform"/>.</summary>
+ private readonly PlatformAssemblyMap AssemblyMap;
/// <summary>A type => assembly lookup for types which should be rewritten.</summary>
private readonly IDictionary<string, Assembly> TypeAssemblies;
@@ -31,22 +28,20 @@ namespace StardewModdingAPI.Framework.AssemblyRewriting
** Public methods
*********/
/// <summary>Construct an instance.</summary>
- /// <param name="targetAssemblies">The assembly filenames to target. Equivalent types will be rewritten to use these assemblies.</param>
- /// <param name="removeAssemblyNames">The short assembly names to remove as assembly reference, and replace with the <paramref name="targetAssemblies"/>.</param>
+ /// <param name="assemblyMap">Metadata for mapping assemblies to the current <see cref="Platform"/>.</param>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
- public AssemblyTypeRewriter(Assembly[] targetAssemblies, string[] removeAssemblyNames, IMonitor monitor)
+ public AssemblyTypeRewriter(PlatformAssemblyMap assemblyMap, IMonitor monitor)
{
// save config
- this.TargetAssemblies = targetAssemblies;
- this.RemoveAssemblyNames = removeAssemblyNames;
+ this.AssemblyMap = assemblyMap;
this.Monitor = monitor;
// cache assembly metadata
- this.AssemblyNameReferences = targetAssemblies.ToDictionary(assembly => assembly, assembly => AssemblyNameReference.Parse(assembly.FullName));
+ this.AssemblyNameReferences = assemblyMap.Targets.ToDictionary(assembly => assembly, assembly => AssemblyNameReference.Parse(assembly.FullName));
// collect type => assembly lookup
this.TypeAssemblies = new Dictionary<string, Assembly>();
- foreach (Assembly assembly in targetAssemblies)
+ foreach (Assembly assembly in assemblyMap.Targets)
{
foreach (Module assemblyModule in assembly.Modules)
{
@@ -73,7 +68,7 @@ namespace StardewModdingAPI.Framework.AssemblyRewriting
// remove old assembly references
for (int i = 0; i < module.AssemblyReferences.Count; i++)
{
- bool shouldRemove = this.RemoveAssemblyNames.Any(name => module.AssemblyReferences[i].Name == name);
+ bool shouldRemove = this.AssemblyMap.RemoveNames.Any(name => module.AssemblyReferences[i].Name == name);
if (shouldRemove)
{
this.Monitor.Log($"removing reference to {module.AssemblyReferences[i]}", LogLevel.Trace);
diff --git a/src/StardewModdingAPI/Framework/AssemblyRewriting/PlatformAssemblyMap.cs b/src/StardewModdingAPI/Framework/AssemblyRewriting/PlatformAssemblyMap.cs
new file mode 100644
index 00000000..3e6cec8a
--- /dev/null
+++ b/src/StardewModdingAPI/Framework/AssemblyRewriting/PlatformAssemblyMap.cs
@@ -0,0 +1,35 @@
+using System.Reflection;
+
+namespace StardewModdingAPI.Framework.AssemblyRewriting
+{
+ /// <summary>Metadata for mapping assemblies to the current <see cref="Platform"/>.</summary>
+ internal class PlatformAssemblyMap
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The target game platform.</summary>
+ public readonly Platform TargetPlatform;
+
+ /// <summary>The short assembly names to remove as assembly reference, and replace with the <see cref="Targets"/>. These should be short names (like "Stardew Valley").</summary>
+ public readonly string[] RemoveNames;
+
+ /// <summary>The assembly filenames to target. Equivalent types should be rewritten to use these assemblies.</summary>
+ public readonly Assembly[] Targets;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="targetPlatform">The target game platform.</param>
+ /// <param name="removeAssemblyNames">The assembly short names to remove (like <c>Stardew Valley</c>).</param>
+ /// <param name="targetAssemblies">The assemblies to target.</param>
+ public PlatformAssemblyMap(Platform targetPlatform, string[] removeAssemblyNames, Assembly[] targetAssemblies)
+ {
+ this.TargetPlatform = targetPlatform;
+ this.RemoveNames = removeAssemblyNames;
+ this.Targets = targetAssemblies;
+ }
+ }
+} \ No newline at end of file