diff --git a/dotnet/src/webdriver/DevTools/DevToolsEventData.cs b/dotnet/src/webdriver/DevTools/DevToolsEventData.cs
index 89cf25fec0624..9f27e3c88fe1e 100644
--- a/dotnet/src/webdriver/DevTools/DevToolsEventData.cs
+++ b/dotnet/src/webdriver/DevTools/DevToolsEventData.cs
@@ -34,7 +34,7 @@ public class DevToolsEventData
/// The type of the event args for the event to be raised.
/// The method that will be used to invoke the event.
/// If or is .
- public DevToolsEventData(Type eventArgsType, Action invoker)
+ public DevToolsEventData(Type eventArgsType, Action invoker)
{
EventArgsType = eventArgsType ?? throw new ArgumentNullException(nameof(eventArgsType));
EventInvoker = invoker ?? throw new ArgumentNullException(nameof(invoker));
@@ -48,6 +48,6 @@ public DevToolsEventData(Type eventArgsType, Action invoker)
///
/// The method to called to raise the event.
///
- public Action EventInvoker { get; }
+ public Action EventInvoker { get; }
}
}
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs b/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs
index eed62654e63fb..48baf369c88d7 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/Utility.cs
@@ -58,7 +58,7 @@ public static string GetTypeMappingForType(TypeDefinition typeDefinition, Domain
{
var primitiveType = typeInfo.TypeName;
- if (typeDefinition.Optional && typeInfo.ByRef)
+ if (typeDefinition.Optional)
{
primitiveType += "?";
}
@@ -70,8 +70,9 @@ public static string GetTypeMappingForType(TypeDefinition typeDefinition, Domain
return primitiveType;
}
+
mappedType = $"{typeInfo.Namespace}.{typeInfo.TypeName}";
- if (typeDefinition.Optional && typeInfo.ByRef)
+ if (typeDefinition.Optional)
{
mappedType += "?";
}
@@ -79,7 +80,7 @@ public static string GetTypeMappingForType(TypeDefinition typeDefinition, Domain
else if (knownTypes.TryGetValue($"{domainDefinition.Name}.{type}", out typeInfo))
{
mappedType = typeInfo.TypeName;
- if (typeInfo.ByRef && typeDefinition.Optional)
+ if (typeDefinition.Optional)
{
mappedType += "?";
}
@@ -89,15 +90,15 @@ public static string GetTypeMappingForType(TypeDefinition typeDefinition, Domain
switch (type)
{
case "number":
- mappedType = typeDefinition.Optional ? "double?" : "double";
+ mappedType = "double";
break;
case "integer":
- mappedType = typeDefinition.Optional ? "long?" : "long";
+ mappedType = "long";
break;
case "boolean":
- mappedType = typeDefinition.Optional ? "bool?" : "bool";
+ mappedType = "bool";
break;
case "string":
@@ -115,12 +116,17 @@ public static string GetTypeMappingForType(TypeDefinition typeDefinition, Domain
case "array":
var items = typeDefinition.Items ?? throw new InvalidOperationException("Type definition was type array but has no Items");
- mappedType = GetTypeMappingForType(items, domainDefinition, knownTypes, true);
+ mappedType = GetTypeMappingForType(items, domainDefinition, knownTypes, isArray: true);
break;
default:
throw new InvalidOperationException($"Unmapped data type: {type}");
}
+
+ if (typeDefinition.Optional)
+ {
+ mappedType += "?";
+ }
}
if (isArray)
diff --git a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs
index db554e452edb5..90db920a116c6 100644
--- a/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs
+++ b/third_party/dotnet/devtools/src/generator/ProtocolDefinition/CommandDefinition.cs
@@ -20,5 +20,8 @@ public sealed class CommandDefinition : ProtocolDefinitionItem
[JsonIgnore]
public bool NoParameters => Parameters == null || Parameters.Count == 0;
+
+ [JsonIgnore]
+ public bool NoReturn => Returns == null || Returns.Count == 0;
}
}
diff --git a/third_party/dotnet/devtools/src/generator/Templates/command.hbs b/third_party/dotnet/devtools/src/generator/Templates/command.hbs
index 19e14c320ddb5..be3f5f7a4d9ee 100644
--- a/third_party/dotnet/devtools/src/generator/Templates/command.hbs
+++ b/third_party/dotnet/devtools/src/generator/Templates/command.hbs
@@ -1,4 +1,7 @@
//
+
+#nullable enable
+
namespace {{rootNamespace}}.{{domain.Name}}
{
using System.Text.Json.Serialization;
@@ -28,7 +31,7 @@ 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; }{{#unless Optional}} = default!;{{/unless}}
{{/each}}
}
@@ -50,7 +53,7 @@ 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; }{{#unless Optional}} = default!;{{/unless}}
{{/each}}
}
diff --git a/third_party/dotnet/devtools/src/generator/Templates/domain.hbs b/third_party/dotnet/devtools/src/generator/Templates/domain.hbs
index 27c483f19d06e..bb6328b290576 100644
--- a/third_party/dotnet/devtools/src/generator/Templates/domain.hbs
+++ b/third_party/dotnet/devtools/src/generator/Templates/domain.hbs
@@ -1,4 +1,7 @@
//
+
+#nullable enable
+
namespace {{rootNamespace}}.{{domain.Name}}
{
using System;
@@ -38,22 +41,24 @@ namespace {{rootNamespace}}.{{domain.Name}}
///
/// {{xml-code-comment Description 2}}
///
- public event EventHandler<{{dehumanize Name}}EventArgs> {{dehumanize Name}};
+ public event EventHandler<{{dehumanize Name}}EventArgs>? {{dehumanize Name}};
{{/each}}
+#nullable disable warnings
{{#each domain.Commands}}
///
/// {{xml-code-comment Description 2}}
///
- 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)
+ public Task<{{dehumanize Name}}CommandResponse{{#if NoReturn}}?{{/if}}> {{dehumanize Name}}({{dehumanize Name}}CommandSettings{{#if NoParameters}}?{{/if}} command{{#if NoParameters}} = null{{/if}}, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
{
return Session.SendCommand<{{dehumanize Name}}CommandSettings, {{dehumanize Name}}CommandResponse>(command{{#if NoParameters}} ?? new {{dehumanize Name}}CommandSettings(){{/if}}, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
}
{{/each}}
+#nullable enable warnings
- private void OnDevToolsEventReceived(object sender, DevToolsEventReceivedEventArgs e)
+ private void OnDevToolsEventReceived(object? sender, DevToolsEventReceivedEventArgs e)
{
if (e.DomainName == m_domainName)
{
@@ -67,7 +72,7 @@ namespace {{rootNamespace}}.{{domain.Name}}
}
{{#each domain.Events}}
- private void On{{dehumanize Name}}(object rawEventArgs)
+ private void On{{dehumanize Name}}(object? rawEventArgs)
{
if (rawEventArgs is {{dehumanize Name}}EventArgs e)
{
diff --git a/third_party/dotnet/devtools/src/generator/Templates/event.hbs b/third_party/dotnet/devtools/src/generator/Templates/event.hbs
index 6b03b19e6cf8c..fb8a6f77a6bfb 100644
--- a/third_party/dotnet/devtools/src/generator/Templates/event.hbs
+++ b/third_party/dotnet/devtools/src/generator/Templates/event.hbs
@@ -1,4 +1,7 @@
//
+
+#nullable enable
+
namespace {{rootNamespace}}.{{domain.Name}}
{
using System;
@@ -21,7 +24,7 @@ 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; }{{#unless Optional}} = default!;{{/unless}}
{{/each}}
}
diff --git a/third_party/dotnet/devtools/src/generator/Templates/type-enum.hbs b/third_party/dotnet/devtools/src/generator/Templates/type-enum.hbs
index a22cb967b80d3..8b6177192c155 100644
--- a/third_party/dotnet/devtools/src/generator/Templates/type-enum.hbs
+++ b/third_party/dotnet/devtools/src/generator/Templates/type-enum.hbs
@@ -1,4 +1,7 @@
//
+
+#nullable enable
+
namespace {{rootNamespace}}.{{domain.Name}}
{
using System.Runtime.Serialization;
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 f5ee9ea1d39df..e6c8ccb12cdc4 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,7 @@
//
+
+#nullable enable
+
namespace {{rootNamespace}}.{{domain.Name}}
{
using System.Collections.Generic;
@@ -14,7 +17,7 @@ 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; }{{#unless Optional}} = default!;{{/unless}}
{{/each}}
}
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 c3e84bc6527b4..cb1ac03d5085c 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,7 @@
//
+
+#nullable enable
+
namespace {{rootNamespace}}.{{domain.Name}}
{
using System.Text.Json.Serialization;
@@ -14,7 +17,7 @@ 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; }{{#unless Optional}} = default!;{{/unless}}
{{/each}}
}