summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Reflection/OriginalInterfaceProxyFactory.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-06-16 22:14:44 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-06-16 22:14:44 -0400
commit8e9237bdd7ec179975c9be5e28c811b42007e707 (patch)
tree665ca44f40e77e8f4a3af55ee442e2b3acba6434 /src/SMAPI/Framework/Reflection/OriginalInterfaceProxyFactory.cs
parente10147e7bda94a8fbc58684246628a6520d2c6b8 (diff)
parent011aa4c9d07d6fc313d6d1ee107651778bb3c665 (diff)
downloadSMAPI-8e9237bdd7ec179975c9be5e28c811b42007e707.tar.gz
SMAPI-8e9237bdd7ec179975c9be5e28c811b42007e707.tar.bz2
SMAPI-8e9237bdd7ec179975c9be5e28c811b42007e707.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/Reflection/OriginalInterfaceProxyFactory.cs')
-rw-r--r--src/SMAPI/Framework/Reflection/OriginalInterfaceProxyFactory.cs57
1 files changed, 0 insertions, 57 deletions
diff --git a/src/SMAPI/Framework/Reflection/OriginalInterfaceProxyFactory.cs b/src/SMAPI/Framework/Reflection/OriginalInterfaceProxyFactory.cs
deleted file mode 100644
index d6966978..00000000
--- a/src/SMAPI/Framework/Reflection/OriginalInterfaceProxyFactory.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Reflection.Emit;
-
-namespace StardewModdingAPI.Framework.Reflection
-{
- /// <inheritdoc />
- internal class OriginalInterfaceProxyFactory : IInterfaceProxyFactory
- {
- /*********
- ** Fields
- *********/
- /// <summary>The CLR module in which to create proxy classes.</summary>
- private readonly ModuleBuilder ModuleBuilder;
-
- /// <summary>The generated proxy types.</summary>
- private readonly IDictionary<string, OriginalInterfaceProxyBuilder> Builders = new Dictionary<string, OriginalInterfaceProxyBuilder>();
-
-
- /*********
- ** Public methods
- *********/
- /// <summary>Construct an instance.</summary>
- public OriginalInterfaceProxyFactory()
- {
- AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName($"StardewModdingAPI.Proxies, Version={this.GetType().Assembly.GetName().Version}, Culture=neutral"), AssemblyBuilderAccess.Run);
- this.ModuleBuilder = assemblyBuilder.DefineDynamicModule("StardewModdingAPI.Proxies");
- }
-
- /// <inheritdoc />
- public TInterface CreateProxy<TInterface>(object instance, string sourceModID, string targetModID)
- where TInterface : class
- {
- lock (this.Builders)
- {
- // validate
- if (instance == null)
- throw new InvalidOperationException("Can't proxy access to a null API.");
- if (!typeof(TInterface).IsInterface)
- throw new InvalidOperationException("The proxy type must be an interface, not a class.");
-
- // get proxy type
- Type targetType = instance.GetType();
- string proxyTypeName = $"StardewModdingAPI.Proxies.From<{sourceModID}_{typeof(TInterface).FullName}>_To<{targetModID}_{targetType.FullName}>";
- if (!this.Builders.TryGetValue(proxyTypeName, out OriginalInterfaceProxyBuilder? builder))
- {
- builder = new OriginalInterfaceProxyBuilder(proxyTypeName, this.ModuleBuilder, typeof(TInterface), targetType);
- this.Builders[proxyTypeName] = builder;
- }
-
- // create instance
- return (TInterface)builder.CreateInstance(instance);
- }
- }
- }
-}