private void GenerateRpcServiceSessionCode( Type type, CodeWriter.CodeWriter w, List <Tuple <MethodInfo, Tuple <string, string> > > method2PayloadTypeNames, Tuple <Type, List <Tuple <MethodInfo, Tuple <string, string> > > >[] typeInfos) { using (w.B($"public class {Utility.GetRpcServiceSessionClassName(type)}{type.GetGenericParameters()} : IRpcInvokable")) { using (w.B($"public async Task<bool> Invoke(object _target_, NetDataReader _reader_, NetDataWriter _writer_)")) { w._("ISession session = _target_ as ISession;"); w._($"var typeEnum = ({Utility.GetInterfaceEnumName(type)})_reader_.ReadInt32();"); using (w.B($"switch(typeEnum)")) { foreach (var m in typeInfos.First().Item2) { var method = m.Item1; var parameters = method.GetParameters(); var paramStr = string.Join(", ", parameters.Select(p => p.GetParameterDeclaration(true))); var returnType = method.ReturnType.GenericTypeArguments.FirstOrDefault(); var returnTaskType = (returnType != null) ? $"Task<{returnType.GetSymbolDisplay(true)}>" : "Task"; w._($"case {Utility.GetInterfaceEnumName(type)}.{method.Name}:"); using (w.i()) { using (w.i("{", "}")) { var parameterNames = string.Join(", ", method.GetParameters().Select(p => p.Name)); foreach (var param in method.GetParameters()) { w._($"{Utility.GetReaderMethod(param)}"); } if (returnType != null) { w._($"var _result_ = await (session as {type.GetSymbolDisplay()}).{method.Name}{method.GetGenericParameters()}({parameterNames});"); w._($"{Utility.GetWriteMethod(returnType, "_result_")}"); } else { w._($"await (session as {type.GetSymbolDisplay()}).{method.Name}{method.GetGenericParameters()}({parameterNames});"); } } w._($"break;"); } } w._($"default: return false;"); } w._($"return true;"); } } }