pschelpdesk/Vendor/Prise.Proxy/ProxyCreator.cs
2024-11-04 20:45:34 +01:00

33 lines
1.1 KiB
C#

using System;
namespace Prise.Proxy
{
public static class ProxyCreator
{
public static object CreateGenericProxy(Type proxyType, object remoteObject)
{
return typeof(ProxyCreator).GetMethod(nameof(ProxyCreator.CreateProxy)).MakeGenericMethod(proxyType).Invoke(null, new[] { remoteObject, null, null });
}
public static TProxyType CreateProxy<TProxyType>(
object remoteObject,
IParameterConverter parameterConverter = null,
IResultConverter resultConverter = null)
{
if (parameterConverter == null)
parameterConverter = new PassthroughParameterConverter();
if (resultConverter == null)
resultConverter = new PassthroughResultConverter();
var proxy = PriseProxy<TProxyType>.Create();
((PriseProxy<TProxyType>)proxy)
.SetRemoteObject(remoteObject)
.SetParameterConverter(parameterConverter)
.SetResultConverter(resultConverter);
return (TProxyType)proxy;
}
}
}