Example #1
0
		static object[] ProcessResponse (IMethodReturnMessage mrm, MonoMethodMessage call)
		{
			// Check return type

			MethodInfo mi = (MethodInfo) call.MethodBase;
			if (mrm.ReturnValue != null && !mi.ReturnType.IsInstanceOfType (mrm.ReturnValue))
				throw new InvalidCastException ("Return value has an invalid type");

			// Check out parameters

			
			int no;
			
			if (call.NeedsOutProcessing (out no))
			{
				ParameterInfo[] parameters = mi.GetParameters();
				object[] outArgs = new object [no];
				int narg = 0;
	
				foreach (ParameterInfo par in parameters)
				{
					if (par.IsOut && !par.ParameterType.IsByRef)
					{
						// Special marshalling required
						object outArg = par.Position < mrm.ArgCount ? mrm.GetArg (par.Position) : null;
						if (outArg != null) {
							object local = call.GetArg (par.Position);
							if (local == null) throw new RemotingException ("Unexpected null value in local out parameter '" + par.Name + "'");
							RemotingServices.UpdateOutArgObject (par, local, outArg);
						}
					}
					else if (par.ParameterType.IsByRef)
					{
						object outArg = par.Position < mrm.ArgCount ? mrm.GetArg (par.Position) : null;
						if (outArg != null && !par.ParameterType.GetElementType ().IsInstanceOfType (outArg))
						{
							throw new InvalidCastException ("Return argument '" + par.Name + "' has an invalid type");
						}
						outArgs [narg++] = outArg;
					}
				}
				return outArgs;
			}
			else
				return new object [0];
		}