From 99df4ba2d96ed14efc43b0531727a0dad111d24c Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 22 Jan 2025 12:52:17 -0500 Subject: [PATCH] [dotnet] Improve format of generated CDP types (#15129) * [dotnet] Improve format of generated cdp types * fix XML param in adapter template --- .../src/generator/Templates/command.hbs | 19 +++++------------ .../src/generator/Templates/domain.hbs | 21 +++++++++---------- .../src/generator/Templates/event.hbs | 7 ++----- .../src/generator/Templates/type-hash.hbs | 11 ++++------ .../src/generator/Templates/type-object.hbs | 11 ++++------ 5 files changed, 25 insertions(+), 44 deletions(-) diff --git a/third_party/dotnet/devtools/src/generator/Templates/command.hbs b/third_party/dotnet/devtools/src/generator/Templates/command.hbs index d1e9ce1a9064d..19e14c320ddb5 100644 --- a/third_party/dotnet/devtools/src/generator/Templates/command.hbs +++ b/third_party/dotnet/devtools/src/generator/Templates/command.hbs @@ -14,10 +14,7 @@ namespace {{rootNamespace}}.{{domain.Name}} /// Gets the name of the command. /// [JsonIgnore] - public string CommandName - { - get { return DevToolsRemoteInterface_CommandName; } - } + public string CommandName => DevToolsRemoteInterface_CommandName; {{#each command.Parameters}} {{#if Description}} @@ -31,11 +28,8 @@ namespace {{rootNamespace}}.{{domain.Name}} {{/if}} [JsonPropertyName("{{Name}}")] {{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}} - public {{typemap ../context}} {{dehumanize Name}} - { - get; - set; - } + public {{typemap ../context}} {{dehumanize Name}} { get; set; } + {{/each}} } @@ -56,11 +50,8 @@ namespace {{rootNamespace}}.{{domain.Name}} {{/if}} [JsonPropertyName("{{Name}}")] {{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}} - public {{typemap ../context}} {{dehumanize Name}} - { - get; - set; - } + public {{typemap ../context}} {{dehumanize Name}} { get; set; } + {{/each}} } } diff --git a/third_party/dotnet/devtools/src/generator/Templates/domain.hbs b/third_party/dotnet/devtools/src/generator/Templates/domain.hbs index 8dc01ba4fb8ea..27c483f19d06e 100644 --- a/third_party/dotnet/devtools/src/generator/Templates/domain.hbs +++ b/third_party/dotnet/devtools/src/generator/Templates/domain.hbs @@ -12,7 +12,6 @@ namespace {{rootNamespace}}.{{domain.Name}} /// public class {{dehumanize domain.Name}}Adapter { - private readonly IDevToolsSession m_session; private readonly string m_domainName = "{{dehumanize domain.Name}}"; private Dictionary m_eventMap = new Dictionary(); @@ -20,10 +19,11 @@ namespace {{rootNamespace}}.{{domain.Name}} /// Initializes a new instance of the {{dehumanize domain.Name}}Adapter class. /// /// The IDevToolsSession to be used with this adapter. + /// If is . public {{dehumanize domain.Name}}Adapter(IDevToolsSession session) { - m_session = session ?? throw new ArgumentNullException(nameof(session)); - m_session.DevToolsEventReceived += OnDevToolsEventReceived; + Session = session ?? throw new ArgumentNullException(nameof(session)); + Session.DevToolsEventReceived += OnDevToolsEventReceived; {{#each domain.Events}} m_eventMap["{{Name}}"] = new DevToolsEventData(typeof({{dehumanize Name}}EventArgs), On{{dehumanize Name}}); {{/each}} @@ -32,16 +32,14 @@ namespace {{rootNamespace}}.{{domain.Name}} /// /// Gets the DevToolsSession associated with the adapter. /// - public IDevToolsSession Session - { - get { return m_session; } - } + public IDevToolsSession Session { get; } {{#each domain.Events}} /// /// {{xml-code-comment Description 2}} /// public event EventHandler<{{dehumanize Name}}EventArgs> {{dehumanize Name}}; + {{/each}} {{#each domain.Commands}} @@ -50,8 +48,9 @@ namespace {{rootNamespace}}.{{domain.Name}} /// 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) { - return m_session.SendCommand<{{dehumanize Name}}CommandSettings, {{dehumanize Name}}CommandResponse>(command{{#if NoParameters}} ?? new {{dehumanize Name}}CommandSettings(){{/if}}, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived); + return Session.SendCommand<{{dehumanize Name}}CommandSettings, {{dehumanize Name}}CommandResponse>(command{{#if NoParameters}} ?? new {{dehumanize Name}}CommandSettings(){{/if}}, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived); } + {{/each}} private void OnDevToolsEventReceived(object sender, DevToolsEventReceivedEventArgs e) @@ -70,12 +69,12 @@ namespace {{rootNamespace}}.{{domain.Name}} {{#each domain.Events}} private void On{{dehumanize Name}}(object rawEventArgs) { - {{dehumanize Name}}EventArgs e = rawEventArgs as {{dehumanize Name}}EventArgs; - if (e != null && {{dehumanize Name}} != null) + if (rawEventArgs is {{dehumanize Name}}EventArgs e) { - {{dehumanize Name}}(this, e); + {{dehumanize Name}}?.Invoke(this, e); } } + {{/each}} } } diff --git a/third_party/dotnet/devtools/src/generator/Templates/event.hbs b/third_party/dotnet/devtools/src/generator/Templates/event.hbs index 5707d3be5c85f..6b03b19e6cf8c 100644 --- a/third_party/dotnet/devtools/src/generator/Templates/event.hbs +++ b/third_party/dotnet/devtools/src/generator/Templates/event.hbs @@ -21,11 +21,8 @@ namespace {{rootNamespace}}.{{domain.Name}} {{/if}} [JsonPropertyName("{{Name}}")] {{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}} - public {{typemap ../context}} {{dehumanize Name}} - { - get; - set; - } + public {{typemap ../context}} {{dehumanize Name}} { get; set; } + {{/each}} } } diff --git a/third_party/dotnet/devtools/src/generator/Templates/type-hash.hbs b/third_party/dotnet/devtools/src/generator/Templates/type-hash.hbs index 7e5efc22ed8d1..f5ee9ea1d39df 100644 --- a/third_party/dotnet/devtools/src/generator/Templates/type-hash.hbs +++ b/third_party/dotnet/devtools/src/generator/Templates/type-hash.hbs @@ -1,4 +1,4 @@ -// +// namespace {{rootNamespace}}.{{domain.Name}} { using System.Collections.Generic; @@ -14,11 +14,8 @@ namespace {{rootNamespace}}.{{domain.Name}} /// [JsonPropertyName("{{Name}}")] {{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}} - public {{typemap ../context}} {{dehumanize Name}} - { - get; - set; - } + public {{typemap ../context}} {{dehumanize Name}} { get; set; } + {{/each}} } -} \ No newline at end of file +} diff --git a/third_party/dotnet/devtools/src/generator/Templates/type-object.hbs b/third_party/dotnet/devtools/src/generator/Templates/type-object.hbs index fc9582431ad97..c3e84bc6527b4 100644 --- a/third_party/dotnet/devtools/src/generator/Templates/type-object.hbs +++ b/third_party/dotnet/devtools/src/generator/Templates/type-object.hbs @@ -1,4 +1,4 @@ -// +// namespace {{rootNamespace}}.{{domain.Name}} { using System.Text.Json.Serialization; @@ -14,11 +14,8 @@ namespace {{rootNamespace}}.{{domain.Name}} /// [JsonPropertyName("{{Name}}")] {{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}} - public {{typemap ../context}} {{dehumanize Name}} - { - get; - set; - } + public {{typemap ../context}} {{dehumanize Name}} { get; set; } + {{/each}} } -} \ No newline at end of file +}