Esempio n. 1
0
        internal CallResult Call(CallInfo info)
        {
            var obj = info.ClassID == Guid.Empty ? mRegistred[info.TypeName] : mIdRegistred[info.ClassID];
			var declaringType = obj?.GetType ();

			var method = declaringType.GetMethod(info.MethodName, 
				BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            object result = null;
            var call = new Action(delegate 
                {
                    result = method.Invoke(obj, method.GetParameters()
                       .Select((p, i) => SuperJsonSerializer.ConvertResult(info.Args[i], p.ParameterType)).ToArray());
                });
            mContext.Invoke(call);
            
            if (method.ReturnType != result?.GetType())
                result = new DeclarationWrapper(result, method.ReturnType);

            return new CallResult
            {
                CallID = info.CallID,
                Result = result
            };
        }
Esempio n. 2
0
        public override CallResult SendCall(CallInfo info)
        {
            var tcs = new TaskCompletionSource <CallResult>();

            mWaitingCalls.TryAdd(info.CallID, tcs);
            var method = info.GetMethodInfo();

            for (int i = 0; i < info.Args.Length; i++)
            {
                var declaredType = method.GetParameters()[i].ParameterType;
                if (declaredType == info.Args[i].GetType())
                {
                    continue;
                }
                var declarationWrapper = new DeclarationWrapper(info.Args[i], declaredType);
                info.Args[i] = declarationWrapper;
            }

            SendData(info);
            mContext.Wait(tcs.Task);
            var result = tcs.Task.Result;

            result.Result = SuperJsonSerializer.ConvertResult(result.Result, method.ReturnType);
            return(result);
        }