summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Reflection/InterfaceProxyGlue.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/Reflection/InterfaceProxyGlue.cs')
-rw-r--r--src/SMAPI/Framework/Reflection/InterfaceProxyGlue.cs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/Reflection/InterfaceProxyGlue.cs b/src/SMAPI/Framework/Reflection/InterfaceProxyGlue.cs
index f98b54a2..38569efa 100644
--- a/src/SMAPI/Framework/Reflection/InterfaceProxyGlue.cs
+++ b/src/SMAPI/Framework/Reflection/InterfaceProxyGlue.cs
@@ -18,5 +18,17 @@ namespace StardewModdingAPI.Framework.Reflection
var builder = this.Factory.GetBuilderByProxyTypeName(proxyTypeName);
return builder.ObtainInstance(toProxy, this.Factory);
}
+
+ /// <summary>Try to unproxy, or get an existing, or create a new proxied instance by its type name.</summary>
+ /// <param name="proxyTypeName">The full name of the proxy type.</param>
+ /// <param name="unproxyTypeName">The full name of the reverse proxy type.</param>
+ /// <param name="toProxy">The target instance to proxy.</param>
+ public object UnproxyOrObtainInstanceForProxyTypeName(string proxyTypeName, string unproxyTypeName, object toProxy)
+ {
+ var unproxyBuilder = this.Factory.GetBuilderByProxyTypeName(unproxyTypeName);
+ if (unproxyBuilder.TryUnproxy(toProxy, out object targetInstance))
+ return targetInstance;
+ return this.ObtainInstanceForProxyTypeName(proxyTypeName, toProxy);
+ }
}
}