public string WriteMethod(int methodIndex, MethodInfo method) { string methodHandler = "mMethodHandler" + methodIndex; IDictionary <string, string> dictionary = new Dictionary <string, string>(); IEnumerable <ParameterInfo> methodCallParameters = method.GetParameters(); IEnumerable <string> specialParameters = Enumerable.Empty <string>(); if (typeof(Task).IsAssignableFrom(method.ReturnType)) { specialParameters = new[] { FormatTypeExtensions.FormatType(typeof(CancellationToken)) + ".None" }; } if (typeof(Task).IsAssignableFrom(method.ReturnType) && methodCallParameters.LastOrDefault()?.ParameterType == typeof(CancellationToken)) { specialParameters = new[] { methodCallParameters.LastOrDefault().Name }; methodCallParameters = methodCallParameters.Take(methodCallParameters.Count() - 1); } if (method.GetCustomAttribute <WampProgressiveResultProcedureAttribute>() != null) { specialParameters = new[] { methodCallParameters.LastOrDefault().Name }.Concat(specialParameters); methodCallParameters = methodCallParameters.Take(methodCallParameters.Count() - 1); } dictionary["methodName"] = method.Name; dictionary["parameterList"] = string.Join(", ", new[] { "this" }.Concat(specialParameters).Concat(methodCallParameters .Select(x => x.Name))); dictionary["returnType"] = FormatTypeExtensions.GetFormattedReturnType(method); if (method.ReturnType != typeof(void)) { dictionary["return"] = "return "; } else { dictionary["return"] = string.Empty; } dictionary["methodHandler"] = methodHandler; dictionary["parametersDeclaration"] = string.Join(", ", method.GetParameters().Select (x => FormatTypeExtensions.FormatType(x.ParameterType) + " " + x.Name)); return(CodeGenerationHelper.ProcessTemplate(mMethodTemplate, dictionary)); }
public string WriteMethod(int methodIndex, MethodInfo method) { string methodHandler = "mMethodHandler" + methodIndex; IDictionary <string, string> dictionary = new Dictionary <string, string>(); ParameterInfo[] parameters = method.GetParameters(); dictionary["array"] = string.Join(", ", (parameters.Select(x => GetCallerParameter(x)))); dictionary["methodName"] = method.Name; dictionary["parameterList"] = string.Join(", ", new[] { "this", "___array" }); Type returnType = method.ReturnType; dictionary["returnType"] = FormatTypeExtensions.GetFormattedReturnType(method); if (returnType != typeof(void)) { dictionary["varResult"] = "var ___result = "; dictionary["return"] = "return ___result;"; } else { dictionary["varResult"] = string.Empty; dictionary["return"] = "return;"; } dictionary["parametersDeclaration"] = string.Join(", ", parameters.Select (x => GetQualifiedName(x, CodeGenerationHelper.GetMethodParameterDeclaration))); dictionary["unpack"] = string.Join(Environment.NewLine, parameters.Where(x => x.IsOut || x.ParameterType.IsByRef) .Select(x => GetUnpackStatement(x))); dictionary["methodHandler"] = methodHandler; return(CodeGenerationHelper.ProcessTemplate(mMethodTemplate, dictionary)); }