Ejemplo n.º 1
0
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg);
            var args = methodMessage.Args;

            Type[]     argumentTypes  = MethodUtil.GetArgTypes(args);
            MethodInfo targetMethod   = GetMethodInfoForMethodBase(methodMessage, argumentTypes);
            object     objReturnValue = null;

            if (targetMethod != null)
            {
                if (targetMethod.Name.Equals("Equals") && argumentTypes != null && argumentTypes.Length == 1 && argumentTypes[0].IsAssignableFrom((typeof(Object))))
                {
                    objReturnValue = false;
                }
                else if (targetMethod.Name.Equals("GetHashCode") && argumentTypes.Length == 0)
                {
                    objReturnValue = _proxyType.GetHashCode();
                }
                else if (targetMethod.Name.Equals("ToString") && argumentTypes.Length == 0)
                {
                    objReturnValue = "[Proxy " + _proxyType.Name + "]";
                }
                else if (targetMethod.Name.Equals("GetType") && argumentTypes.Length == 0)
                {
                    objReturnValue = _proxyType;
                }
                else
                {
                    objReturnValue = DoMethodCall(args, argumentTypes, targetMethod);
                }
            }
            else
            {
                if (targetMethod.Name.Equals("GetType") && (args.Length == 0))
                {
                    objReturnValue = _proxyType;
                }
            }
            return(new ReturnMessage(objReturnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage));
        }
Ejemplo n.º 2
0
        protected override object Invoke(MethodInfo targetMethod, object[] args)
        {
            Type[] argumentTypes  = MethodUtil.GetArgTypes(args);
            object objReturnValue = null;

            if (targetMethod != null)
            {
                if (targetMethod.Name.Equals("Equals") && argumentTypes != null && argumentTypes.Length == 1 && argumentTypes[0].IsAssignableFrom((typeof(Object))))
                {
                    objReturnValue = false;
                }
                else if (targetMethod.Name.Equals("GetHashCode") && argumentTypes.Length == 0)
                {
                    objReturnValue = _proxyType.GetHashCode();
                }
                else if (targetMethod.Name.Equals("ToString") && argumentTypes.Length == 0)
                {
                    objReturnValue = "[Proxy " + _proxyType.Name + "]";
                }
                else if (targetMethod.Name.Equals("GetType") && argumentTypes.Length == 0)
                {
                    objReturnValue = _proxyType;
                }
                else
                {
                    objReturnValue = DoMethodCall(args, argumentTypes, targetMethod);
                }
            }
            else
            {
                if (targetMethod.Name.Equals("GetType") && (args.Length == 0))
                {
                    objReturnValue = _proxyType;
                }
            }
            return(objReturnValue);
        }