summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Reflection/InterfaceProxyGlue.cs
blob: f98b54a2d074af94737a2d41cff165f3ea38f6e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
namespace StardewModdingAPI.Framework.Reflection
{
    /// <summary>Provides an interface for proxied types to create other proxied types.</summary>
    public sealed class InterfaceProxyGlue
    {
        private readonly InterfaceProxyFactory Factory;

        internal InterfaceProxyGlue(InterfaceProxyFactory factory)
        {
            this.Factory = factory;
        }

        /// <summary>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="toProxy">The target instance to proxy.</param>
        public object ObtainInstanceForProxyTypeName(string proxyTypeName, object toProxy)
        {
            var builder = this.Factory.GetBuilderByProxyTypeName(proxyTypeName);
            return builder.ObtainInstance(toProxy, this.Factory);
        }
    }
}