/// <summary>
        /// 通过反射调用有返回方法
        /// </summary>
        /// <typeparam name="T">返回类型</typeparam>
        /// <param name="obj">调用实例</param>
        /// <param name="methodName">方法名称</param>
        /// <param name="parameters">输入参数</param>
        /// <returns></returns>
        public static T MethodInvoke <T>(this IInvokeHelper instance, object obj, string methodName, params object[] parameters)
        {
            MethodInfo mdi = obj?.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public);

            if (mdi != null)
            {
                return((T)mdi?.Invoke(obj, parameters));
            }
            return(default);
Exemple #2
0
        private static void AsyncInvoke <TCallback>(HproseInvoker invoker, string methodName, object[] args, TCallback callback, HproseErrorEvent errorEvent)
        {
            if (callback is HproseCallback)
            {
                invoker.Invoke(methodName, args, callback as HproseCallback, errorEvent);
            }
            else if (callback is HproseCallback1)
            {
                invoker.Invoke(methodName, args, callback as HproseCallback1, errorEvent);
            }
            else
            {
#if Core
                TypeInfo type = callback.GetType().GetTypeInfo();
                if (type.IsGenericType)
                {
                    if (type.GetGenericTypeDefinition() == typeof(HproseCallback <>))
                    {
                        IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(type.GenericTypeArguments)) as IInvokeHelper;
                        helper.Invoke(invoker, methodName, args, callback as Delegate, errorEvent, false, HproseResultMode.Normal, false);
                        return;
                    }
                    else if (type.GetGenericTypeDefinition() == typeof(HproseCallback1 <>))
                    {
                        IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(type.GenericTypeArguments)) as IInvokeHelper1;
                        helper.Invoke(invoker, methodName, args, callback as Delegate, errorEvent, HproseResultMode.Normal, false);
                        return;
                    }
                }
#else
                Type type = callback.GetType();
                if (type.IsGenericType)
                {
                    if (type.GetGenericTypeDefinition() == typeof(HproseCallback <>))
                    {
                        IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(type.GetGenericArguments())) as IInvokeHelper;
                        helper.Invoke(invoker, methodName, args, callback as Delegate, errorEvent, false, HproseResultMode.Normal, false);
                        return;
                    }
                    else if (type.GetGenericTypeDefinition() == typeof(HproseCallback1 <>))
                    {
                        IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(type.GetGenericArguments())) as IInvokeHelper1;
                        helper.Invoke(invoker, methodName, args, callback as Delegate, errorEvent, HproseResultMode.Normal, false);
                        return;
                    }
                }
#endif
                throw new Exception("TCallback must be a Callback Delegate: HproseCallback, HproseCallback1, HproseCallback<T>, HproseCallback1<T>.");
            }
        }
        /// <summary>
        /// 通过反射调用无返回方法
        /// </summary>
        /// <param name="obj">调用实例</param>
        /// <param name="methodName">方法名称</param>
        /// <param name="parameters"></param>
        public static void MethodInvoke(this IInvokeHelper instance, object obj, string methodName, params object[] parameters)
        {
            MethodInfo mdi = obj?.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public);

            _ = mdi?.Invoke(obj, parameters);
        }
Exemple #4
0
        public object Invoke(object proxy, MethodInfo method, object[] args)
        {
            ParameterInfo[] parameters = method.GetParameters();
            Type[]          paramTypes = GetTypes(parameters);
            Type            returnType = method.ReturnType;

            if (returnType == typeof(void))
            {
                returnType = null;
            }
            int    n            = paramTypes.Length;
            string functionName = method.Name;

            if (ns != null)
            {
                functionName = ns + '_' + functionName;
            }
            bool byRef = false;

            foreach (Type param in paramTypes)
            {
                if (param.IsByRef)
                {
                    byRef = true;
                    break;
                }
            }
            if ((n > 0) && (paramTypes[n - 1] == typeof(HproseCallback)))
            {
                HproseCallback callback = (HproseCallback)args[n - 1];
                object[]       tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                client.Invoke(functionName, tmpargs, callback, byRef);
                return(null);
            }
            if ((n > 0) && (paramTypes[n - 1] == typeof(HproseCallback1)))
            {
                HproseCallback1 callback = (HproseCallback1)args[n - 1];
                object[]        tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                client.Invoke(functionName, tmpargs, callback);
                return(null);
            }
            if ((n > 1) && (paramTypes[n - 2] == typeof(HproseCallback)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback callback = (HproseCallback)args[n - 2];
                returnType = (Type)args[n - 1];
                object[] tmpargs = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                client.Invoke(functionName, tmpargs, callback, returnType, byRef);
                return(null);
            }
            if ((n > 1) && (paramTypes[n - 2] == typeof(HproseCallback1)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback1 callback = (HproseCallback1)args[n - 2];
                returnType = (Type)args[n - 1];
                object[] tmpargs = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                client.Invoke(functionName, tmpargs, callback, returnType);
                return(null);
            }
#if !(dotNET10 || dotNET11 || dotNETCF10)
            if ((n > 0) && (paramTypes[n - 1].IsGenericType &&
                            (paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback <>))))
            {
                IInvokeHelper helper   = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper;
                Delegate      callback = (Delegate)args[n - 1];
                object[]      tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                helper.Invoke(client, functionName, tmpargs, callback, byRef);
                return(null);
            }
            if ((n > 0) && (paramTypes[n - 1].IsGenericType &&
                            (paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback1 <>))))
            {
                IInvokeHelper1 helper   = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper1;
                Delegate       callback = (Delegate)args[n - 1];
                object[]       tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                helper.Invoke(client, functionName, tmpargs, callback);
                return(null);
            }
#endif
#if SILVERLIGHT
            throw new HproseException("SilverLight do not support synchronous invoke.");
#else
            object result = client.Invoke(functionName, args, returnType, byRef);
            if (result is Exception)
            {
                throw (Exception)result;
            }
            return(result);
#endif
        }
        public object Invoke(object proxy, string methodName, Type[] paramTypes, Type returnType, object[] attrs, object[] args)
        {
#endif
            HproseResultMode resultMode = HproseResultMode.Normal;
            bool             simple     = false;
            bool             byRef      = false;
#if !dotNETMF
            foreach (Type param in paramTypes)
            {
                if (param.IsByRef)
                {
                    byRef = true;
                    break;
                }
            }
#endif
            foreach (object attr in attrs)
            {
                if (attr is ResultModeAttribute)
                {
                    resultMode = (attr as ResultModeAttribute).Value;
                }
                else if (attr is SimpleModeAttribute)
                {
                    simple = (attr as SimpleModeAttribute).Value;
                }
                else if (attr is ByRefAttribute)
                {
                    byRef = (attr as ByRefAttribute).Value;
                }
                else if (attr is MethodNameAttribute)
                {
                    methodName = (attr as MethodNameAttribute).Value;
                }
            }
            CheckResultType(resultMode, returnType);
            if (ns != null && ns != "")
            {
                methodName = ns + '_' + methodName;
            }
#if (dotNET4 || SL5 || WP80) && !(SL4 || WP70 || WP71)
#if Core
            if (returnType.GetTypeInfo().IsGenericType&&
                returnType.GetGenericTypeDefinition() == typeof(Task <>))
            {
                ITaskCreator taskCreator = Activator.CreateInstance(typeof(TaskCreator <>).MakeGenericType(returnType.GenericTypeArguments)) as ITaskCreator;
#else
            if (returnType.IsGenericType &&
                returnType.GetGenericTypeDefinition() == typeof(Task <>))
            {
                ITaskCreator taskCreator = Activator.CreateInstance(typeof(TaskCreator <>).MakeGenericType(returnType.GetGenericArguments())) as ITaskCreator;
#endif
                return(taskCreator.GetTask(invoker, methodName, args, byRef, resultMode, simple));
            }
            if (returnType == typeof(Task))
            {
#if dotNET45
                return(Task.Run(delegate() {
                    invoker.Invoke(methodName, args, (Type)null, byRef, resultMode, simple);
                }));
#else
                return(Task.Factory.StartNew(delegate() {
                    invoker.Invoke(methodName, args, (Type)null, byRef, resultMode, simple);
                }, default(CancellationToken), TaskCreationOptions.None, TaskScheduler.Default));
#endif
            }
#endif
            int n = paramTypes.Length;
            if ((n > 0) && (paramTypes[n - 1] == typeof(HproseCallback)))
            {
                HproseCallback callback = (HproseCallback)args[n - 1];
                object[]       tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                invoker.Invoke(methodName, tmpargs, callback, byRef, resultMode, simple);
                return(null);
            }
            if ((n > 0) && (paramTypes[n - 1] == typeof(HproseCallback1)))
            {
                HproseCallback1 callback = (HproseCallback1)args[n - 1];
                object[]        tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                invoker.Invoke(methodName, tmpargs, callback);
                return(null);
            }
            if ((n > 1) && (paramTypes[n - 2] == typeof(HproseCallback)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback callback = (HproseCallback)args[n - 2];
                returnType = (Type)args[n - 1];
                CheckResultType(resultMode, returnType);
                object[] tmpargs = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                invoker.Invoke(methodName, tmpargs, callback, returnType, byRef, resultMode, simple);
                return(null);
            }
            if ((n > 1) && (paramTypes[n - 2] == typeof(HproseCallback1)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback1 callback = (HproseCallback1)args[n - 2];
                returnType = (Type)args[n - 1];
                CheckResultType(resultMode, returnType);
                object[] tmpargs = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                invoker.Invoke(methodName, tmpargs, callback, returnType, resultMode, simple);
                return(null);
            }
            if ((n > 2) && (paramTypes[n - 3] == typeof(HproseCallback)) &&
                (paramTypes[n - 2] == typeof(HproseErrorEvent)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback   callback   = (HproseCallback)args[n - 3];
                HproseErrorEvent errorEvent = (HproseErrorEvent)args[n - 2];
                returnType = (Type)args[n - 1];
                CheckResultType(resultMode, returnType);
                object[] tmpargs = new object[n - 3];
                Array.Copy(args, 0, tmpargs, 0, n - 3);
                invoker.Invoke(methodName, tmpargs, callback, errorEvent, returnType, byRef, resultMode, simple);
                return(null);
            }
            if ((n > 2) && (paramTypes[n - 3] == typeof(HproseCallback1)) &&
                (paramTypes[n - 2] == typeof(HproseErrorEvent)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback1  callback   = (HproseCallback1)args[n - 3];
                HproseErrorEvent errorEvent = (HproseErrorEvent)args[n - 2];
                returnType = (Type)args[n - 1];
                CheckResultType(resultMode, returnType);
                object[] tmpargs = new object[n - 3];
                Array.Copy(args, 0, tmpargs, 0, n - 3);
                invoker.Invoke(methodName, tmpargs, callback, errorEvent, returnType, resultMode, simple);
                return(null);
            }
#if !(dotNET10 || dotNET11 || dotNETCF10 || dotNETMF)
#if Core
            if ((n > 0) && paramTypes[n - 1].GetTypeInfo().IsGenericType&&
                paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback <>))
            {
                IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(paramTypes[n - 1].GenericTypeArguments)) as IInvokeHelper;
#else
            if ((n > 0) && paramTypes[n - 1].IsGenericType &&
                paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback <>))
            {
                IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper;
#endif
                Delegate callback = (Delegate)args[n - 1];
                object[] tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                helper.Invoke(invoker, methodName, tmpargs, callback, null, byRef, resultMode, simple);
                return(null);
            }
#if Core
            if ((n > 0) && paramTypes[n - 1].GetTypeInfo().IsGenericType&&
                paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback1 <>))
            {
                IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(paramTypes[n - 1].GenericTypeArguments)) as IInvokeHelper1;
#else
            if ((n > 0) && paramTypes[n - 1].IsGenericType &&
                paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback1 <>))
            {
                IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper1;
#endif
                Delegate callback = (Delegate)args[n - 1];
                object[] tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                helper.Invoke(invoker, methodName, tmpargs, callback, null, resultMode, simple);
                return(null);
            }
#if Core
            if ((n > 1) && paramTypes[n - 2].GetTypeInfo().IsGenericType&&
                paramTypes[n - 2].GetGenericTypeDefinition() == typeof(HproseCallback <>) &&
                paramTypes[n - 1] == typeof(HproseErrorEvent))
            {
                IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(paramTypes[n - 1].GenericTypeArguments)) as IInvokeHelper;
#else
            if ((n > 1) && paramTypes[n - 2].IsGenericType &&
                paramTypes[n - 2].GetGenericTypeDefinition() == typeof(HproseCallback <>) &&
                paramTypes[n - 1] == typeof(HproseErrorEvent))
            {
                IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper;
#endif
                Delegate         callback   = (Delegate)args[n - 2];
                HproseErrorEvent errorEvent = (HproseErrorEvent)args[n - 1];
                object[]         tmpargs    = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                helper.Invoke(invoker, methodName, tmpargs, callback, errorEvent, byRef, resultMode, simple);
                return(null);
            }
#if Core
            if ((n > 1) && paramTypes[n - 2].GetTypeInfo().IsGenericType&&
                paramTypes[n - 2].GetGenericTypeDefinition() == typeof(HproseCallback1 <>) &&
                paramTypes[n - 1] == typeof(HproseErrorEvent))
            {
                IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(paramTypes[n - 1].GenericTypeArguments)) as IInvokeHelper1;
#else
            if ((n > 1) && paramTypes[n - 2].IsGenericType &&
                paramTypes[n - 2].GetGenericTypeDefinition() == typeof(HproseCallback1 <>) &&
                paramTypes[n - 1] == typeof(HproseErrorEvent))
            {
                IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper1;
#endif
                Delegate         callback   = (Delegate)args[n - 2];
                HproseErrorEvent errorEvent = (HproseErrorEvent)args[n - 1];
                object[]         tmpargs    = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                helper.Invoke(invoker, methodName, tmpargs, callback, errorEvent, resultMode, simple);
                return(null);
            }
#endif
            if (returnType == typeof(void))
            {
                returnType = null;
            }
            return(invoker.Invoke(methodName, args, returnType, byRef, resultMode, simple));
        }
Exemple #6
0
        public object Invoke(object proxy, MethodInfo method, object[] args)
        {
            ParameterInfo[]  parameters = method.GetParameters();
            HproseResultMode resultMode = HproseResultMode.Normal;
            bool             simple     = false;
            string           methodName = method.Name;

#if dotNET45
            Attribute rmAttr = method.GetCustomAttribute(typeof(ResultModeAttribute), true);
            if (rmAttr != null)
            {
                resultMode = (rmAttr as ResultModeAttribute).Value;
            }
            Attribute smAttr = method.GetCustomAttribute(typeof(SimpleModeAttribute), true);
            if (smAttr != null)
            {
                simple = (smAttr as SimpleModeAttribute).Value;
            }
            Attribute mnAttr = method.GetCustomAttribute(typeof(MethodNameAttribute), true);
            if (mnAttr != null)
            {
                methodName = (mnAttr as MethodNameAttribute).Value;
            }
#else
            object[] resultModes = method.GetCustomAttributes(typeof(ResultModeAttribute), true);
            if (resultModes.Length == 1)
            {
                resultMode = (resultModes[0] as ResultModeAttribute).Value;
            }
            object[] simpleModes = method.GetCustomAttributes(typeof(SimpleModeAttribute), true);
            if (simpleModes.Length == 1)
            {
                simple = (simpleModes[0] as SimpleModeAttribute).Value;
            }
            object[] methodNames = method.GetCustomAttributes(typeof(MethodNameAttribute), true);
            if (methodNames.Length == 1)
            {
                methodName = (methodNames[0] as MethodNameAttribute).Value;
            }
#endif
            if (ns != null && ns != "")
            {
                methodName = ns + '_' + methodName;
            }
            Type returnType = method.ReturnType;
            CheckResultType(resultMode, returnType);
            bool   byRef      = false;
            Type[] paramTypes = GetTypes(parameters);
            foreach (Type param in paramTypes)
            {
                if (param.IsByRef)
                {
                    byRef = true;
                    break;
                }
            }
#if dotNET45
#if Core
            if (returnType.GetTypeInfo().IsGenericType&&
                returnType.GetGenericTypeDefinition() == typeof(Task <>))
            {
                ITaskCreator taskCreator = Activator.CreateInstance(typeof(TaskCreator <>).MakeGenericType(returnType.GenericTypeArguments)) as ITaskCreator;
#else
            if (returnType.IsGenericType &&
                returnType.GetGenericTypeDefinition() == typeof(Task <>))
            {
                ITaskCreator taskCreator = Activator.CreateInstance(typeof(TaskCreator <>).MakeGenericType(returnType.GetGenericArguments())) as ITaskCreator;
#endif
                return(taskCreator.GetTask(invoker, methodName, args, byRef, resultMode, simple));
            }
            if (returnType == typeof(Task))
            {
                return(Task.Run(delegate() {
                    invoker.Invoke(methodName, args, (Type)null, byRef, resultMode, simple);
                }));
            }
#endif
            int n = paramTypes.Length;
            if ((n > 0) && (paramTypes[n - 1] == typeof(HproseCallback)))
            {
                HproseCallback callback = (HproseCallback)args[n - 1];
                object[]       tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                invoker.Invoke(methodName, tmpargs, callback, byRef, resultMode, simple);
                return(null);
            }
            if ((n > 0) && (paramTypes[n - 1] == typeof(HproseCallback1)))
            {
                HproseCallback1 callback = (HproseCallback1)args[n - 1];
                object[]        tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                invoker.Invoke(methodName, tmpargs, callback);
                return(null);
            }
            if ((n > 1) && (paramTypes[n - 2] == typeof(HproseCallback)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback callback = (HproseCallback)args[n - 2];
                returnType = (Type)args[n - 1];
                CheckResultType(resultMode, returnType);
                object[] tmpargs = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                invoker.Invoke(methodName, tmpargs, callback, returnType, byRef, resultMode, simple);
                return(null);
            }
            if ((n > 1) && (paramTypes[n - 2] == typeof(HproseCallback1)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback1 callback = (HproseCallback1)args[n - 2];
                returnType = (Type)args[n - 1];
                CheckResultType(resultMode, returnType);
                object[] tmpargs = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                invoker.Invoke(methodName, tmpargs, callback, returnType, resultMode, simple);
                return(null);
            }
            if ((n > 2) && (paramTypes[n - 3] == typeof(HproseCallback)) &&
                (paramTypes[n - 2] == typeof(HproseErrorEvent)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback   callback   = (HproseCallback)args[n - 3];
                HproseErrorEvent errorEvent = (HproseErrorEvent)args[n - 2];
                returnType = (Type)args[n - 1];
                CheckResultType(resultMode, returnType);
                object[] tmpargs = new object[n - 3];
                Array.Copy(args, 0, tmpargs, 0, n - 3);
                invoker.Invoke(methodName, tmpargs, callback, errorEvent, returnType, byRef, resultMode, simple);
                return(null);
            }
            if ((n > 2) && (paramTypes[n - 3] == typeof(HproseCallback1)) &&
                (paramTypes[n - 2] == typeof(HproseErrorEvent)) &&
                (paramTypes[n - 1] == typeof(Type)))
            {
                HproseCallback1  callback   = (HproseCallback1)args[n - 3];
                HproseErrorEvent errorEvent = (HproseErrorEvent)args[n - 2];
                returnType = (Type)args[n - 1];
                CheckResultType(resultMode, returnType);
                object[] tmpargs = new object[n - 3];
                Array.Copy(args, 0, tmpargs, 0, n - 3);
                invoker.Invoke(methodName, tmpargs, callback, errorEvent, returnType, resultMode, simple);
                return(null);
            }
#if !(dotNET10 || dotNET11 || dotNETCF10)
#if Core
            if ((n > 0) && paramTypes[n - 1].GetTypeInfo().IsGenericType&&
                paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback <>))
            {
                IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(paramTypes[n - 1].GenericTypeArguments)) as IInvokeHelper;
#else
            if ((n > 0) && paramTypes[n - 1].IsGenericType &&
                paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback <>))
            {
                IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper;
#endif
                Delegate callback = (Delegate)args[n - 1];
                object[] tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                helper.Invoke(invoker, methodName, tmpargs, callback, null, byRef, resultMode, simple);
                return(null);
            }
#if Core
            if ((n > 0) && paramTypes[n - 1].GetTypeInfo().IsGenericType&&
                paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback1 <>))
            {
                IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(paramTypes[n - 1].GenericTypeArguments)) as IInvokeHelper1;
#else
            if ((n > 0) && paramTypes[n - 1].IsGenericType &&
                paramTypes[n - 1].GetGenericTypeDefinition() == typeof(HproseCallback1 <>))
            {
                IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper1;
#endif
                Delegate callback = (Delegate)args[n - 1];
                object[] tmpargs  = new object[n - 1];
                Array.Copy(args, 0, tmpargs, 0, n - 1);
                helper.Invoke(invoker, methodName, tmpargs, callback, null, resultMode, simple);
                return(null);
            }
#if Core
            if ((n > 1) && paramTypes[n - 2].GetTypeInfo().IsGenericType&&
                paramTypes[n - 2].GetGenericTypeDefinition() == typeof(HproseCallback <>) &&
                paramTypes[n - 1] == typeof(HproseErrorEvent))
            {
                IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(paramTypes[n - 1].GenericTypeArguments)) as IInvokeHelper;
#else
            if ((n > 1) && paramTypes[n - 2].IsGenericType &&
                paramTypes[n - 2].GetGenericTypeDefinition() == typeof(HproseCallback <>) &&
                paramTypes[n - 1] == typeof(HproseErrorEvent))
            {
                IInvokeHelper helper = Activator.CreateInstance(typeof(InvokeHelper <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper;
#endif
                Delegate         callback   = (Delegate)args[n - 2];
                HproseErrorEvent errorEvent = (HproseErrorEvent)args[n - 1];
                object[]         tmpargs    = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                helper.Invoke(invoker, methodName, tmpargs, callback, errorEvent, byRef, resultMode, simple);
                return(null);
            }
#if Core
            if ((n > 1) && paramTypes[n - 2].GetTypeInfo().IsGenericType&&
                paramTypes[n - 2].GetGenericTypeDefinition() == typeof(HproseCallback1 <>) &&
                paramTypes[n - 1] == typeof(HproseErrorEvent))
            {
                IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(paramTypes[n - 1].GenericTypeArguments)) as IInvokeHelper1;
#else
            if ((n > 1) && paramTypes[n - 2].IsGenericType &&
                paramTypes[n - 2].GetGenericTypeDefinition() == typeof(HproseCallback1 <>) &&
                paramTypes[n - 1] == typeof(HproseErrorEvent))
            {
                IInvokeHelper1 helper = Activator.CreateInstance(typeof(InvokeHelper1 <>).MakeGenericType(paramTypes[n - 1].GetGenericArguments())) as IInvokeHelper1;
#endif
                Delegate         callback   = (Delegate)args[n - 2];
                HproseErrorEvent errorEvent = (HproseErrorEvent)args[n - 1];
                object[]         tmpargs    = new object[n - 2];
                Array.Copy(args, 0, tmpargs, 0, n - 2);
                helper.Invoke(invoker, methodName, tmpargs, callback, errorEvent, resultMode, simple);
                return(null);
            }
#endif
            if (returnType == typeof(void))
            {
                returnType = null;
            }
            return(invoker.Invoke(methodName, args, returnType, byRef, resultMode, simple));
        }
    }
}