ValidateReturnArg() private static method

private static ValidateReturnArg ( Object arg, Type paramType ) : void
arg Object
paramType System.Type
return void
示例#1
0
        internal static void PropagateOutParameters(IMessage msg, object[] outArgs, object returnValue)
        {
            Message message = msg as Message;

            if (message == null)
            {
                ConstructorCallMessage constructorCallMessage = msg as ConstructorCallMessage;
                if (constructorCallMessage != null)
                {
                    message = constructorCallMessage.GetMessage();
                }
            }
            if (message == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Remoting_Proxy_ExpectedOriginalMessage"));
            }
            RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(message.GetMethodBase());

            if (outArgs != null && outArgs.Length != 0)
            {
                object[]        args       = message.Args;
                ParameterInfo[] parameters = reflectionCachedData.Parameters;
                foreach (int marshalRequestArg in reflectionCachedData.MarshalRequestArgMap)
                {
                    ParameterInfo parameterInfo = parameters[marshalRequestArg];
                    if (parameterInfo.IsIn && parameterInfo.ParameterType.IsByRef && !parameterInfo.IsOut)
                    {
                        outArgs[marshalRequestArg] = args[marshalRequestArg];
                    }
                }
                if (reflectionCachedData.NonRefOutArgMap.Length != 0)
                {
                    foreach (int nonRefOutArg in reflectionCachedData.NonRefOutArgMap)
                    {
                        Array array = args[nonRefOutArg] as Array;
                        if (array != null)
                        {
                            Array sourceArray      = (Array)outArgs[nonRefOutArg];
                            Array destinationArray = array;
                            int   length           = destinationArray.Length;
                            Array.Copy(sourceArray, destinationArray, length);
                        }
                    }
                }
                int[] outRefArgMap = reflectionCachedData.OutRefArgMap;
                if (outRefArgMap.Length != 0)
                {
                    foreach (int index in outRefArgMap)
                    {
                        RealProxy.ValidateReturnArg(outArgs[index], parameters[index].ParameterType);
                    }
                }
            }
            if ((message.GetCallType() & 15) != 1)
            {
                Type returnType = reflectionCachedData.ReturnType;
                if (returnType != (Type)null)
                {
                    RealProxy.ValidateReturnArg(returnValue, returnType);
                }
            }
            message.PropagateOutParameters(outArgs, returnValue);
        }