summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModHelpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/ModHelpers')
-rw-r--r--src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs37
1 files changed, 6 insertions, 31 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs
index 92c52b00..93ea6028 100644
--- a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using Nanoray.Pintail;
using StardewModdingAPI.Framework.Reflection;
namespace StardewModdingAPI.Framework.ModHelpers
@@ -19,7 +20,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
private readonly HashSet<string> AccessedModApis = new HashSet<string>();
/// <summary>Generates proxy classes to access mod APIs through an arbitrary interface.</summary>
- private readonly InterfaceProxyFactory ProxyFactory;
+ private readonly IProxyManager<string> ProxyManager;
/*********
@@ -28,13 +29,13 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>Construct an instance.</summary>
/// <param name="modID">The unique ID of the relevant mod.</param>
/// <param name="registry">The underlying mod registry.</param>
- /// <param name="proxyFactory">Generates proxy classes to access mod APIs through an arbitrary interface.</param>
+ /// <param name="proxyManager">Generates proxy classes to access mod APIs through an arbitrary interface.</param>
/// <param name="monitor">Encapsulates monitoring and logging for the mod.</param>
- public ModRegistryHelper(string modID, ModRegistry registry, InterfaceProxyFactory proxyFactory, IMonitor monitor)
+ public ModRegistryHelper(string modID, ModRegistry registry, IProxyManager<string> proxyManager, IMonitor monitor)
: base(modID)
{
this.Registry = registry;
- this.ProxyFactory = proxyFactory;
+ this.ProxyManager = proxyManager;
this.Monitor = monitor;
}
@@ -96,33 +97,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
// get API of type
if (api is TInterface castApi)
return castApi;
- return this.ProxyFactory.CreateProxy<TInterface>(api, this.ModID, uniqueID);
- }
-
- /// <inheritdoc />
- public bool TryProxy<TInterface>(string uniqueID, object toProxy, out TInterface proxy) where TInterface : class
- {
- try
- {
- foreach (var toProxyInterface in toProxy.GetType().GetInterfaces())
- {
- var unproxyBuilder = this.ProxyFactory.ObtainBuilder(typeof(TInterface), toProxyInterface, this.ModID, uniqueID);
- if (unproxyBuilder.TryUnproxy(toProxy, out object targetInstance))
- {
- proxy = (TInterface)targetInstance;
- return true;
- }
- }
-
- var proxyBuilder = this.ProxyFactory.ObtainBuilder(toProxy.GetType(), typeof(TInterface), this.ModID, uniqueID);
- proxy = (TInterface)proxyBuilder.ObtainInstance(toProxy, this.ProxyFactory);
- return true;
- }
- catch
- {
- proxy = null;
- return false;
- }
+ return this.ProxyManager.ObtainProxy<string, TInterface>(api, this.ModID, uniqueID);
}
}
}