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 }; }
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); }
public override SuperToken Serialize(object obj, Type declaredType, SuperJsonSerializer serializer) { if (obj is bool) { return(new SuperBool((bool)obj)); } return(new SuperNumber((double)SuperJsonSerializer.ConvertResult(obj, typeof(double)))); }
void ReciveData(TaskResult result) { var tcs = WaitingTasks[result.TaskID]; switch (result.Status) { case TaskCompletionStatus.Canceled: tcs.SetCanceled(); break; case TaskCompletionStatus.Exception: tcs.SetException((Exception)result.Result); break; case TaskCompletionStatus.Result: tcs.SetResult(SuperJsonSerializer.ConvertResult(result.Result, tcs.GetType().GetGenericArguments()[0])); break; default: throw new Exception("Holy Moly!"); } }