using System.Reflection; using System.Reflection.Emit; using Nanoray.Pintail; namespace StardewModdingAPI.Framework.Reflection { /// internal class InterfaceProxyFactory : IInterfaceProxyFactory { /********* ** Fields *********/ /// The underlying proxy type builder. private readonly IProxyManager ProxyManager; /********* ** Public methods *********/ /// Construct an instance. public InterfaceProxyFactory() { AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName($"StardewModdingAPI.Proxies, Version={this.GetType().Assembly.GetName().Version}, Culture=neutral"), AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("StardewModdingAPI.Proxies"); this.ProxyManager = new ProxyManager(moduleBuilder, new ProxyManagerConfiguration( proxyPrepareBehavior: ProxyManagerProxyPrepareBehavior.Eager, proxyObjectInterfaceMarking: ProxyObjectInterfaceMarking.Disabled )); } /// public TInterface CreateProxy(object instance, string sourceModID, string targetModID) where TInterface : class { return this.ProxyManager.ObtainProxy(instance, targetContext: targetModID, proxyContext: sourceModID); } } }