2 // System.Runtime.Remoting.StackBuilderSink.cs
4 // Author: Lluis Sanchez Gual (lsg@ctv.es)
6 // (C) 2002, Lluis Sanchez Gual
10 using System.Reflection;
12 namespace System.Runtime.Remoting.Messaging
14 // Sink that calls the real method of the object
16 public class StackBuilderSink: IMessageSink
18 MarshalByRefObject _target;
20 public StackBuilderSink (MarshalByRefObject obj)
25 public IMessage SyncProcessMessage (IMessage msg)
27 CheckParameters (msg);
29 // Makes the real call to the object
30 return RemotingServices.InternalExecuteMessage (_target, (IMethodCallMessage)msg);
34 public IMessageCtrl AsyncProcessMessage (IMessage msg, IMessageSink replySink)
36 throw new NotImplementedException ();
39 public IMessageSink NextSink
44 void CheckParameters (IMessage msg)
46 IMethodCallMessage mcm = (IMethodCallMessage) msg;
48 MethodInfo mi = (MethodInfo) mcm.MethodBase;
50 ParameterInfo[] parameters = mi.GetParameters();
53 foreach (ParameterInfo pi in parameters)
55 object pval = mcm.GetArg (narg++);
56 Type pt = pi.ParameterType;
57 if (pt.IsByRef) pt = pt.GetElementType ();
59 if (pval != null && !pt.IsInstanceOfType (pval))
60 throw new RemotingException ("Cannot cast argument of type '" + pval.GetType().AssemblyQualifiedName +
61 "' to type '" + pt.AssemblyQualifiedName + "'");