diff options
| author | mo k <mo@mokhan.ca> | 2012-05-03 12:44:39 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-05-03 12:44:39 -0600 |
| commit | 2ea2730e65af8e7849c6f36443f87e8731ffd5be (patch) | |
| tree | 3b9455098690e0038d0f04754b4c34a91cd34162 /proxies/RemotingProxyFactory.cs | |
initial checkin.main
Diffstat (limited to 'proxies/RemotingProxyFactory.cs')
| -rw-r--r-- | proxies/RemotingProxyFactory.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/proxies/RemotingProxyFactory.cs b/proxies/RemotingProxyFactory.cs new file mode 100644 index 0000000..d0c862b --- /dev/null +++ b/proxies/RemotingProxyFactory.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic;
+using System.Runtime.Remoting.Messaging;
+using System.Runtime.Remoting.Proxies;
+
+namespace proxies
+{
+ public class RemotingProxyFactory<T> : RealProxy
+ {
+ private readonly T target;
+ private readonly IEnumerable<IInterceptor> interceptors;
+
+ public RemotingProxyFactory(T target, IEnumerable<IInterceptor> interceptors) : base(typeof (T))
+ {
+ this.target = target;
+ this.interceptors = interceptors;
+ }
+
+ public override IMessage Invoke(IMessage message)
+ {
+ if (message.is_a<IMethodCallMessage>())
+ {
+ var call = message.downcast_to<IMethodCallMessage>();
+ var invocation = new MethodCallInvocation<T>(interceptors, call, target);
+ invocation.Proceed();
+ return ReturnValue(invocation.ReturnValue, invocation.Arguments, call);
+ }
+ return null;
+ }
+
+ private IMessage ReturnValue(object return_value, object[] out_parameters, IMethodCallMessage call)
+ {
+ return new ReturnMessage(return_value,
+ out_parameters,
+ out_parameters == null ? 0 : out_parameters.Length,
+ call.LogicalCallContext, call);
+ }
+
+ public T CreateProxy()
+ {
+ return GetTransparentProxy().downcast_to<T>();
+ }
+ }
+}
\ No newline at end of file |
