diff --git a/third_party/dotnet/devtools/src/generator/BUILD.bazel b/third_party/dotnet/devtools/src/generator/BUILD.bazel
index f202cd9df6387..7d466358b4772 100644
--- a/third_party/dotnet/devtools/src/generator/BUILD.bazel
+++ b/third_party/dotnet/devtools/src/generator/BUILD.bazel
@@ -3,7 +3,7 @@ load("//dotnet:defs.bzl", "csharp_binary", "framework")
csharp_binary(
name = "generator",
srcs = glob(["**/*.cs"]),
- nullable = "annotations",
+ nullable = "enable",
# Used as a tool in our build, so just target one framework
target_frameworks = ["net8.0"],
visibility = [
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs
index b9049b2b08ba3..329a2ad0bd449 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationSettings.cs
@@ -36,7 +36,7 @@ public sealed class CodeGenerationSettings
/// Gets the version number of the runtime.
///
[JsonPropertyName("runtimeVersion")]
- public string RuntimeVersion { get; set; }
+ public string? RuntimeVersion { get; set; }
[JsonPropertyName("definitionTemplates")]
public CodeGenerationDefinitionTemplateSettings DefinitionTemplates { get; set; } = new CodeGenerationDefinitionTemplateSettings();
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs
index 99a9a2be31123..caa40da3171c5 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGenerationTemplateSettings.cs
@@ -8,9 +8,11 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
public class CodeGenerationTemplateSettings
{
[JsonPropertyName("templatePath")]
- public string TemplatePath { get; set; }
+ [JsonRequired]
+ public string TemplatePath { get; set; } = null!;
[JsonPropertyName("outputPath")]
- public string OutputPath { get; set; }
+ [JsonRequired]
+ public string OutputPath { get; set; } = null!;
}
}
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs
index d142a3a622154..e89124b4d7500 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorBase.cs
@@ -10,7 +10,7 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
///
///
public abstract class CodeGeneratorBase : ICodeGenerator
- where T : IDefinition
+ where T : class, IDefinition
{
private readonly Lazy m_settings;
private readonly Lazy m_templatesManager;
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs
index 07ce4735c19da..d81b84b4902d5 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/CodeGeneratorContext.cs
@@ -6,10 +6,10 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
///
/// Represents the current context of the code generator.
///
- public sealed class CodeGeneratorContext
+ public sealed class CodeGeneratorContext(DomainDefinition domain, Dictionary knownTypes)
{
- public DomainDefinition Domain { get; set; }
+ public DomainDefinition Domain { get; } = domain;
- public Dictionary KnownTypes { get; set; }
+ public Dictionary KnownTypes { get; } = knownTypes;
}
}
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/CommandInfo.cs b/third_party/dotnet/devtools/src/generator/CodeGen/CommandInfo.cs
index f70dfd4601861..b898880d4e356 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/CommandInfo.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/CommandInfo.cs
@@ -3,12 +3,12 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
///
/// Represents information about a Chrome Debugger Protocol command.
///
- public sealed class CommandInfo
+ public sealed class CommandInfo(string commandName, string fullTypeName, string fullResponseTypeName)
{
- public string CommandName { get; set; }
+ public string CommandName { get; } = commandName;
- public string FullTypeName { get; set; }
+ public string FullTypeName { get; } = fullTypeName;
- public string FullResponseTypeName { get; set; }
+ public string FullResponseTypeName { get; } = fullResponseTypeName;
}
}
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/EventInfo.cs b/third_party/dotnet/devtools/src/generator/CodeGen/EventInfo.cs
index 0e78b688ac880..2ed7bbd74fd6f 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/EventInfo.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/EventInfo.cs
@@ -3,10 +3,10 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
///
/// Represents information about a Chrome Debugger Protocol event.
///
- public sealed class EventInfo
+ public sealed class EventInfo(string eventName, string fullTypeName)
{
- public string EventName { get; set; }
+ public string EventName { get; } = eventName;
- public string FullTypeName { get; set; }
+ public string FullTypeName { get; } = fullTypeName;
}
}
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/ICodeGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/ICodeGenerator.cs
index 004fcb65ad21f..6620a5c5cda2a 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/ICodeGenerator.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/ICodeGenerator.cs
@@ -8,7 +8,7 @@ namespace OpenQA.Selenium.DevToolsGenerator.CodeGen
///
///
public interface ICodeGenerator
- where T : IDefinition
+ where T : class, IDefinition
{
///
/// Generates one or more code files for the specified IDefinition item
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs b/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs
index 660b44c07b125..9abf949722b53 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/ProtocolGenerator.cs
@@ -3,6 +3,7 @@
using OpenQA.Selenium.DevToolsGenerator.ProtocolDefinition;
using System;
using System.Collections.Generic;
+using System.Data;
using System.IO;
using System.Linq;
@@ -22,7 +23,7 @@ public override IDictionary GenerateCode(ProtocolDefinition.Prot
{
if (string.IsNullOrWhiteSpace(Settings.TemplatesPath))
{
- Settings.TemplatesPath = Path.GetDirectoryName(Settings.TemplatesPath);
+ Settings.TemplatesPath = Path.GetDirectoryName(Settings.TemplatesPath)!;
}
ICollection domains = protocolDefinition.Domains;
@@ -44,11 +45,11 @@ public override IDictionary GenerateCode(ProtocolDefinition.Prot
foreach (var command in domain.Commands)
{
commands.Add(new CommandInfo
- {
- CommandName = $"{domain.Name}.{command.Name}",
- FullTypeName = $"{domain.Name.Dehumanize()}.{command.Name.Dehumanize()}CommandSettings",
- FullResponseTypeName = $"{domain.Name.Dehumanize()}.{command.Name.Dehumanize()}CommandResponse"
- });
+ (
+ commandName: $"{domain.Name}.{command.Name}",
+ fullTypeName: $"{domain.Name.Dehumanize()}.{command.Name.Dehumanize()}CommandSettings",
+ fullResponseTypeName: $"{domain.Name.Dehumanize()}.{command.Name.Dehumanize()}CommandResponse"
+ ));
}
}
@@ -60,10 +61,10 @@ public override IDictionary GenerateCode(ProtocolDefinition.Prot
foreach (var @event in domain.Events)
{
events.Add(new EventInfo
- {
- EventName = $"{domain.Name}.{@event.Name}",
- FullTypeName = $"{domain.Name.Dehumanize()}.{@event.Name.Dehumanize()}EventArgs"
- });
+ (
+ eventName: $"{domain.Name}.{@event.Name}",
+ fullTypeName: $"{domain.Name.Dehumanize()}.{@event.Name.Dehumanize()}EventArgs")
+ );
}
}
@@ -102,7 +103,7 @@ public override IDictionary GenerateCode(ProtocolDefinition.Prot
return result;
}
- private Dictionary GetTypesInDomain(ICollection domains)
+ private static Dictionary GetTypesInDomain(ICollection domains)
{
var knownTypes = new Dictionary(StringComparer.OrdinalIgnoreCase);
@@ -116,9 +117,9 @@ private Dictionary GetTypesInDomain(ICollection 0)
{
- TypeDefinition propertyTypeDefinition = new TypeDefinition()
+ string id = $"{type.Id.Dehumanize()}{propertyType.Name.Dehumanize()}Values";
+ TypeDefinition propertyTypeDefinition = new TypeDefinition(id)
{
- Id = type.Id.Dehumanize() + propertyType.Name.Dehumanize() + "Values",
Type = propertyType.Type,
Description = $"Enumerated values for {domain.Name}.{type.Id}.{propertyType.Name}"
};
@@ -136,35 +137,33 @@ private Dictionary GetTypesInDomain(ICollection 0)
{
- typeInfo = new TypeInfo
+ typeInfo = new TypeInfo(typeName: type.Id.Dehumanize(), isPrimitive: false)
{
ByRef = true,
- IsPrimitive = false,
- TypeName = type.Id.Dehumanize(),
};
}
else
{
- typeInfo = new TypeInfo
- {
- IsPrimitive = true,
- TypeName = "string"
- };
+ typeInfo = new TypeInfo("string", isPrimitive: true);
}
break;
+
case "array":
- if ((type.Items == null || string.IsNullOrWhiteSpace(type.Items.Type)) &&
- type.Items.TypeReference != "StringIndex" && type.Items.TypeReference != "FilterEntry")
+ if (type.Items is null)
+ {
+ throw new InvalidOperationException("Type definition's Type was array but Items is missing");
+ }
+
+ if (string.IsNullOrWhiteSpace(type.Items.Type) &&
+ type.Items.TypeReference != "StringIndex" &&
+ type.Items.TypeReference != "FilterEntry")
{
throw new NotImplementedException("Did not expect a top-level domain array type to specify a TypeReference");
}
@@ -199,28 +198,23 @@ private Dictionary GetTypesInDomain(ICollection GetTypesInDomain(ICollection GenerateCode(ICollection do
//Generate types/events/commands for all domains.
foreach (var domain in domains)
{
- var context = new CodeGeneratorContext { Domain = domain, KnownTypes = knownTypes };
+ var context = new CodeGeneratorContext(domain, knownTypes);
foreach (KeyValuePair x in domainGenerator.GenerateCode(domain, context))
{
result.Add(x.Key, x.Value);
diff --git a/third_party/dotnet/devtools/src/generator/CodeGen/TemplatesManager.cs b/third_party/dotnet/devtools/src/generator/CodeGen/TemplatesManager.cs
index 4921ab04cbb46..7b13a0e0178fb 100644
--- a/third_party/dotnet/devtools/src/generator/CodeGen/TemplatesManager.cs
+++ b/third_party/dotnet/devtools/src/generator/CodeGen/TemplatesManager.cs
@@ -34,9 +34,9 @@ public TemplatesManager(CodeGenerationSettings settings)
public Func