* ArgInfo.cs: Use Type.IsByRef to check if a parameter is a ref or
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / StackBuilderSink.cs
1 //
2 // System.Runtime.Remoting.StackBuilderSink.cs
3 //
4 // Author: Lluis Sanchez Gual (lsg@ctv.es)
5 //
6 // (C) 2002, Lluis Sanchez Gual
7 //
8
9 using System;
10 using System.Reflection;
11
12 namespace System.Runtime.Remoting.Messaging
13 {
14         // Sink that calls the real method of the object
15
16         public class StackBuilderSink: IMessageSink
17         {
18                 MarshalByRefObject _target;
19
20                 public StackBuilderSink (MarshalByRefObject obj)
21                 {
22                         _target = obj;
23                 }
24
25                 public IMessage SyncProcessMessage (IMessage msg)
26                 {
27                         CheckParameters (msg);
28
29                         // Makes the real call to the object
30                         return RemotingServices.InternalExecuteMessage (_target, (IMethodCallMessage)msg);
31                 }
32
33                 [MonoTODO]
34                 public IMessageCtrl AsyncProcessMessage (IMessage msg, IMessageSink replySink)
35                 {
36                         throw new NotImplementedException ();
37                 }
38
39                 public IMessageSink NextSink 
40                 { 
41                         get { return null; }
42                 }
43
44                 void CheckParameters (IMessage msg)
45                 {
46                         IMethodCallMessage mcm = (IMethodCallMessage) msg;
47                         
48                         MethodInfo mi = (MethodInfo) mcm.MethodBase;
49
50                         ParameterInfo[] parameters = mi.GetParameters();
51                         int narg = 0;
52
53                         foreach (ParameterInfo pi in parameters)
54                         {
55                                 object pval = mcm.GetArg (narg++);
56                                 Type pt = pi.ParameterType;
57                                 if (pt.IsByRef) pt = pt.GetElementType ();
58                                 
59                                 if (pval != null && !pt.IsInstanceOfType (pval))
60                                         throw new RemotingException ("Cannot cast argument of type '" + pval.GetType().AssemblyQualifiedName +
61                                                 "' to type '" + pt.AssemblyQualifiedName + "'");
62                         }
63                 }
64         }
65 }