Skip to content

Commit b41c82f

Browse files
committed
Handle command serialization/response deserialization within the domain
1 parent 5c78d24 commit b41c82f

File tree

1 file changed

+11
-2
lines changed
  • third_party/dotnet/devtools/src/generator/Templates

1 file changed

+11
-2
lines changed

third_party/dotnet/devtools/src/generator/Templates/domain.hbs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,18 @@ namespace {{rootNamespace}}.{{domain.Name}}
4646
/// <summary>
4747
/// {{xml-code-comment Description 2}}
4848
/// </summary>
49-
public Task<{{dehumanize Name}}CommandResponse> {{dehumanize Name}}({{dehumanize Name}}CommandSettings command{{#if NoParameters}} = null{{/if}}, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
49+
public async Task<{{dehumanize Name}}CommandResponse> {{dehumanize Name}}({{dehumanize Name}}CommandSettings command{{#if NoParameters}} = null{{/if}}, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
5050
{
51-
return Session.SendCommand<{{dehumanize Name}}CommandSettings, {{dehumanize Name}}CommandResponse>(command{{#if NoParameters}} ?? new {{dehumanize Name}}CommandSettings(){{/if}}, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
51+
{{#if NoParameters}}command ??= new {{dehumanize Name}}CommandSettings();{{/if}}
52+
global::System.Text.Json.Nodes.JsonNode serializedCommand = global::System.Text.Json.JsonSerializer.SerializeToNode(command);
53+
global::System.Text.Json.JsonElement? response = await Session.SendCommand(command.CommandName, serializedCommand, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived).ConfigureAwait(false);
54+
55+
if (response == null)
56+
{
57+
return default({{dehumanize Name}}CommandResponse);
58+
}
59+
60+
return global::System.Text.Json.JsonSerializer.Deserialize<{{dehumanize Name}}CommandResponse>(response.Value);
5261
}
5362

5463
{{/each}}

0 commit comments

Comments
 (0)