Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
zijianhuang committed Jun 22, 2024
1 parent 7e9aa70 commit 9f49d8e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions WebApiClientGenCore/ClientApiFunctionGen.cs
Original file line number Diff line number Diff line change
@@ -425,21 +425,20 @@ void AddRequestUriWithQueryAssignmentStatement()
{
if (codeGenOutputsSettings.UseSystemTextJson)
{
//clientMethod.Statements.Add(new CodeSnippetStatement(ThreeTabs + $"var contentJson = JsonSerializer.Serialize({singleFromBodyParameterDescription.ParameterDescriptor.ParameterName}, jsonSerializerSettings);"));
clientMethod.Statements.Add(new CodeSnippetStatement(ThreeTabs + $"var content = System.Net.Http.Json.JsonContent.Create({singleFromBodyParameterDescription.ParameterDescriptor.ParameterName}, mediaType: null, jsonSerializerSettings);"));
}
else
{
clientMethod.Statements.Add(new CodeSnippetStatement(
$"\t\t\tusing var requestWriter = new System.IO.StringWriter();{Environment.NewLine}\t\t\tvar requestSerializer = JsonSerializer.Create(jsonSerializerSettings);"
));
$"\t\t\tusing var requestWriter = new System.IO.StringWriter();{Environment.NewLine}\t\t\tvar requestSerializer = JsonSerializer.Create(jsonSerializerSettings);"
));
clientMethod.Statements.Add(new CodeMethodInvokeExpression(new CodeSnippetExpression("requestSerializer"), "Serialize",
new CodeSnippetExpression("requestWriter"),
new CodeSnippetExpression(singleFromBodyParameterDescription.ParameterDescriptor.ParameterName)));


clientMethod.Statements.Add(new CodeSnippetStatement(
@" var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, ""application/json"");"
"\t\t\tvar content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, \"application/json\");"
));
}

0 comments on commit 9f49d8e

Please sign in to comment.