internal static void ReturnContentObject(BodyAttribute bodyAttr, Type returnType, bool isAsyncCall, StringBuilder classBuilder) { if (bodyAttr == null || returnType == null) { return; } var format = bodyAttr.Format; if (format == Format.Auto) { format = typeof(Stream).IsAssignableFrom(returnType) ? Format.Raw : Format.Json; } // The Format.Auto is handled above, since it will always be Raw or Json at this point // ReSharper disable once SwitchStatementMissingSomeCases switch (format) { case Format.Json: classBuilder.AppendLine(isAsyncCall ? $" return await ConvertToObjectAsync<{WebServiceClassGenerator.ToCompilableName(returnType)}>(response);" : $" return ConvertToObject<{WebServiceClassGenerator.ToCompilableName(returnType)}>(response);"); break; case Format.Raw: classBuilder.AppendLine(isAsyncCall ? " return await response.Content.ReadAsStreamAsync();" : " return response.Content.ReadAsStreamAsync().Result;"); break; default: return; } }
//public string CreateInterface(string srvName,string route,string requestMethod,string returnType, List<ParameterModel> paramsList) // { // logger.LogDebug($"Create a interface by servcer name : {srvName}"); // var sourceCode = WebServiceClassGenerator.GenerateInterfaceSource(srvName, route,requestMethod, returnType,paramsList, out var fullyQualifiedClassName); // syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(sourceCode)); // logger.LogDebug($"Finished compiling the syntax tree for {fullyQualifiedClassName}"); // return fullyQualifiedClassName; // } public string RegisterInterface(TypeInfo type) { logger.LogDebug($"Registering the interface: {type.FullName}"); UpdateReferences(type.Assembly); var sourceCode = WebServiceClassGenerator.GenerateSource(type, out var fullyQualifiedClassName); syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(sourceCode)); logger.LogDebug($"Finished compiling the syntax tree for {fullyQualifiedClassName} generated from {type.FullName}"); return(fullyQualifiedClassName); }
internal static void ReturnResponseHeader(ResponseHeaderAttribute responseHeaderAttribute, Type returnType, StringBuilder classBuilder) { classBuilder.AppendLine($" return GetHeaderValue<{WebServiceClassGenerator.ToCompilableName(returnType)}>(response, \"{responseHeaderAttribute.Header}\");"); }