Skip to content

Commit

Permalink
[dotnet] Improve format of generated CDP types (#15129)
Browse files Browse the repository at this point in the history
* [dotnet] Improve format of generated cdp types

* fix XML param in adapter template
  • Loading branch information
RenderMichael authored Jan 22, 2025
1 parent bad5038 commit 99df4ba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 44 deletions.
19 changes: 5 additions & 14 deletions third_party/dotnet/devtools/src/generator/Templates/command.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ namespace {{rootNamespace}}.{{domain.Name}}
/// Gets the name of the command.
/// </summary>
[JsonIgnore]
public string CommandName
{
get { return DevToolsRemoteInterface_CommandName; }
}
public string CommandName => DevToolsRemoteInterface_CommandName;

{{#each command.Parameters}}
{{#if Description}}
Expand All @@ -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}}
}

Expand All @@ -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}}
}
}
21 changes: 10 additions & 11 deletions third_party/dotnet/devtools/src/generator/Templates/domain.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ namespace {{rootNamespace}}.{{domain.Name}}
/// </summary>
public class {{dehumanize domain.Name}}Adapter
{
private readonly IDevToolsSession m_session;
private readonly string m_domainName = "{{dehumanize domain.Name}}";
private Dictionary<string, DevToolsEventData> m_eventMap = new Dictionary<string, DevToolsEventData>();

/// <summary>
/// Initializes a new instance of the {{dehumanize domain.Name}}Adapter class.
/// </summary>
/// <param name="session">The IDevToolsSession to be used with this adapter.</param>
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
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}}
Expand All @@ -32,16 +32,14 @@ namespace {{rootNamespace}}.{{domain.Name}}
/// <summary>
/// Gets the DevToolsSession associated with the adapter.
/// </summary>
public IDevToolsSession Session
{
get { return m_session; }
}
public IDevToolsSession Session { get; }

{{#each domain.Events}}
/// <summary>
/// {{xml-code-comment Description 2}}
/// </summary>
public event EventHandler<{{dehumanize Name}}EventArgs> {{dehumanize Name}};

{{/each}}

{{#each domain.Commands}}
Expand All @@ -50,8 +48,9 @@ namespace {{rootNamespace}}.{{domain.Name}}
/// </summary>
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)
Expand All @@ -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}}
}
}
7 changes: 2 additions & 5 deletions third_party/dotnet/devtools/src/generator/Templates/event.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
namespace {{rootNamespace}}.{{domain.Name}}
{
using System.Collections.Generic;
Expand All @@ -14,11 +14,8 @@ namespace {{rootNamespace}}.{{domain.Name}}
///</summary>
[JsonPropertyName("{{Name}}")]
{{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}}
public {{typemap ../context}} {{dehumanize Name}}
{
get;
set;
}
public {{typemap ../context}} {{dehumanize Name}} { get; set; }

{{/each}}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
namespace {{rootNamespace}}.{{domain.Name}}
{
using System.Text.Json.Serialization;
Expand All @@ -14,11 +14,8 @@ namespace {{rootNamespace}}.{{domain.Name}}
///</summary>
[JsonPropertyName("{{Name}}")]
{{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}}
public {{typemap ../context}} {{dehumanize Name}}
{
get;
set;
}
public {{typemap ../context}} {{dehumanize Name}} { get; set; }

{{/each}}
}
}
}

0 comments on commit 99df4ba

Please sign in to comment.