Пример #1
0
        private void Init(RPCCallObject o)
        {
            Token = o;
            Type type = o.GetType();

            var methos = type.GetMethods();

            foreach (var item in methos)
            {
                if (item.IsPublic)
                {
                    string methodName = item.Name;
                    var    args       = item.GetParameters();

                    Type[] typeArg = new Type[args.Length];

                    for (int i = 0; i < args.Length; i++)
                    {
                        typeArg[i] = args[i].ParameterType;
                    }

                    methodName = Make.MakeMethodName(methodName, typeArg);
                    if (!MethodInfoDiy.ContainsKey(methodName))
                    {
                        MethodInfoDiy.Add(methodName, new MethodModuleDef(item));
                    }
                }
            }
        }
Пример #2
0
        public override IMessage Invoke(IMessage reqMsg)
        {
            IMethodCallMessage ctorMsg = reqMsg as IMethodCallMessage;


            List <byte[]> arglist = new List <byte[]>(ctorMsg.ArgCount);

            Type[] types = ctorMsg.MethodSignature as Type[];

            Type[] argsType = new Type[ctorMsg.ArgCount];

            object[] args = ctorMsg.Args;

            for (int i = 0; i < ctorMsg.ArgCount; i++)
            {
                argsType[i] = args[i].GetType();
                arglist.Add(Serialization.PackSingleObject(argsType[i], args[i]));
            }

            var returnType = (ctorMsg.MethodBase as MethodInfo).ReturnType;

            if (returnType != nullType)
            {
                if (CallHaveReturn == null)
                {
                    throw new Exception("event not register");
                }
                ProxyReturnValue returnval = CallHaveReturn(Tag, Make.MakeMethodName(ctorMsg.MethodName, types), argsType, arglist, returnType);
                if (returnval.Args == null)
                {
                    returnval.Args = args;
                }

                return(new ReturnMessage(returnval.returnVal, returnval.Args, returnval.Args == null ? 0 : returnval.Args.Length, null, ctorMsg));
            }
            else
            {
                if (CallNullReturn == null)
                {
                    throw new Exception("event not register");
                }

                CallNullReturn(Tag, Make.MakeMethodName(ctorMsg.MethodName, types), argsType, arglist); //如果你没有返回值那么out ref将失效


                return(new ReturnMessage(null, args, args == null ? 0 : args.Length, null, ctorMsg));
            }
        }
Пример #3
0
        private void Init(RPCCallObject o)
        {
            Token = o;
            Type type = o.GetType();

            string tag = Make.GetTypeTag(type);

            if (!string.IsNullOrEmpty(tag))
            {
                ModuleName = tag;
            }


            var methos = type.GetMethods();

            foreach (var item in methos)
            {
                string _methosName;
                if (item.IsPublic)
                {
                    string methodName = item.Name;

                    if (Make.IsCallMethod(item, out _methosName))
                    {
                        if (!string.IsNullOrEmpty(_methosName))
                        {
                            methodName = _methosName;
                        }
                    }

                    var args = item.GetParameters();

                    Type[] typeArg = new Type[args.Length];

                    for (int i = 0; i < args.Length; i++)
                    {
                        typeArg[i] = args[i].ParameterType;
                    }

                    methodName = Make.MakeMethodName(methodName, typeArg);

                    if (!MethodInfoDiy.ContainsKey(methodName))
                    {
                        MethodInfoDiy.Add(methodName, new MethodModuleDef(item));
                    }
                }
            }
        }