Exemplo n.º 1
0
        private object InvokeGatewayMethod(IMethodInvocation invocation)
        {
            if (!_initialized)
            {
                AfterPropertiesSet();
            }
            MethodInfo        method   = invocation.Method;
            IMessagingGateway gateway  = _gatewayMap[method];
            Type   returnType          = method.ReturnType;
            bool   isReturnTypeMessage = typeof(IMessage).IsAssignableFrom(returnType);
            bool   shouldReply         = returnType != typeof(void);
            int    paramCount          = method.GetParameters().Length;
            object response            = null;

            if (paramCount == 0)
            {
                if (shouldReply)
                {
                    if (isReturnTypeMessage)
                    {
                        return(gateway.Receive());
                    }
                    response = gateway.Receive();
                }
            }
            else
            {
                object[] args = invocation.Arguments;
                if (shouldReply)
                {
                    response = isReturnTypeMessage ? gateway.SendAndReceiveMessage(args) : gateway.SendAndReceive(args);
                }
                else
                {
                    gateway.Send(args);
                    response = null;
                }
            }
            return((response != null) ? TypeConversionUtils.ConvertValueIfNecessary(returnType, response, null) : null);
        }