Exemplo n.º 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]);
            }
        }
Exemplo n.º 2
0
        private static object[] ProcessResponse(IMethodReturnMessage mrm, MonoMethodMessage call)
        {
            MethodInfo methodInfo = (MethodInfo)call.MethodBase;

            if (mrm.ReturnValue != null && !methodInfo.ReturnType.IsInstanceOfType(mrm.ReturnValue))
            {
                throw new InvalidCastException("Return value has an invalid type");
            }
            int num;

            if (call.NeedsOutProcessing(out num))
            {
                ParameterInfo[] parameters = methodInfo.GetParameters();
                object[]        array      = new object[num];
                int             num2       = 0;
                foreach (ParameterInfo parameterInfo in parameters)
                {
                    if (parameterInfo.IsOut && !parameterInfo.ParameterType.IsByRef)
                    {
                        object obj = (parameterInfo.Position >= mrm.ArgCount) ? null : mrm.GetArg(parameterInfo.Position);
                        if (obj != null)
                        {
                            object arg = call.GetArg(parameterInfo.Position);
                            if (arg == null)
                            {
                                throw new RemotingException("Unexpected null value in local out parameter '" + parameterInfo.Name + "'");
                            }
                            RemotingServices.UpdateOutArgObject(parameterInfo, arg, obj);
                        }
                    }
                    else if (parameterInfo.ParameterType.IsByRef)
                    {
                        object obj2 = (parameterInfo.Position >= mrm.ArgCount) ? null : mrm.GetArg(parameterInfo.Position);
                        if (obj2 != null && !parameterInfo.ParameterType.GetElementType().IsInstanceOfType(obj2))
                        {
                            throw new InvalidCastException("Return argument '" + parameterInfo.Name + "' has an invalid type");
                        }
                        array[num2++] = obj2;
                    }
                }
                return(array);
            }
            return(new object[0]);
        }