Skip to content

Commit 3b51850

Browse files
committed
[dotnet] Annotate nullability for DriverService and some derived types
1 parent 835c8a0 commit 3b51850

File tree

3 files changed

+80
-153
lines changed

3 files changed

+80
-153
lines changed

dotnet/src/webdriver/Chromium/ChromiumDriverService.cs

Lines changed: 33 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
using System.Globalization;
2222
using System.Text;
2323

24+
#nullable enable
25+
2426
namespace OpenQA.Selenium.Chromium
2527
{
2628
/// <summary>
@@ -30,15 +32,6 @@ public abstract class ChromiumDriverService : DriverService
3032
{
3133
private const string DefaultChromeDriverServiceExecutableName = "chromedriver";
3234

33-
private string logPath = string.Empty;
34-
private string urlPathPrefix = string.Empty;
35-
private string portServerAddress = string.Empty;
36-
private string allowedIPAddresses = string.Empty;
37-
private int adbPort = -1;
38-
private bool disableBuildCheck;
39-
private bool enableVerboseLogging;
40-
private bool enableAppendLog;
41-
4235
/// <summary>
4336
/// Initializes a new instance of the <see cref="ChromiumDriverService"/> class.
4437
/// </summary>
@@ -51,71 +44,47 @@ protected ChromiumDriverService(string executablePath, string executableFileName
5144
}
5245

5346
/// <summary>
54-
/// Gets or sets the location of the log file written to by the ChromeDriver executable.
47+
/// <para>Gets or sets the location of the log file written to by the ChromeDriver executable.</para>
48+
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no log path.</para>
5549
/// </summary>
56-
public string LogPath
57-
{
58-
get { return this.logPath; }
59-
set { this.logPath = value; }
60-
}
50+
public string? LogPath { get; set; } = string.Empty;
6151

6252
/// <summary>
63-
/// Gets or sets the base URL path prefix for commands (e.g., "wd/url").
53+
/// <para>Gets or sets the base URL path prefix for commands (e.g., "wd/url").</para>
54+
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no prefix.</para>
6455
/// </summary>
65-
public string UrlPathPrefix
66-
{
67-
get { return this.urlPathPrefix; }
68-
set { this.urlPathPrefix = value; }
69-
}
56+
public string? UrlPathPrefix { get; set; } = string.Empty;
7057

7158
/// <summary>
72-
/// Gets or sets the address of a server to contact for reserving a port.
59+
/// <para>Gets or sets the address of a server to contact for reserving a port.</para>
60+
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no port server.</para>
7361
/// </summary>
74-
public string PortServerAddress
75-
{
76-
get { return this.portServerAddress; }
77-
set { this.portServerAddress = value; }
78-
}
62+
public string PortServerAddress { get; set; } = string.Empty;
7963

8064
/// <summary>
81-
/// Gets or sets the port on which the Android Debug Bridge is listening for commands.
65+
/// <para>Gets or sets the port on which the Android Debug Bridge is listening for commands.</para>
66+
/// <para>A value less than or equal to 0 indicates no Android Debug Bridge specified.</para>
8267
/// </summary>
83-
public int AndroidDebugBridgePort
84-
{
85-
get { return this.adbPort; }
86-
set { this.adbPort = value; }
87-
}
68+
public int AndroidDebugBridgePort { get; set; } = -1;
8869

8970
/// <summary>
9071
/// Gets or sets a value indicating whether to skip version compatibility check
9172
/// between the driver and the browser.
9273
/// Defaults to <see langword="false"/>.
9374
/// </summary>
94-
public bool DisableBuildCheck
95-
{
96-
get { return this.disableBuildCheck; }
97-
set { this.disableBuildCheck = value; }
98-
}
75+
public bool DisableBuildCheck { get; set; }
9976

10077
/// <summary>
10178
/// Gets or sets a value indicating whether to enable verbose logging for the ChromeDriver executable.
10279
/// Defaults to <see langword="false"/>.
10380
/// </summary>
104-
public bool EnableVerboseLogging
105-
{
106-
get { return this.enableVerboseLogging; }
107-
set { this.enableVerboseLogging = value; }
108-
}
81+
public bool EnableVerboseLogging { get; set; }
10982

11083
/// <summary>
11184
/// Gets or sets a value indicating whether to enable appending to an existing ChromeDriver log file.
11285
/// Defaults to <see langword="false"/>.
11386
/// </summary>
114-
public bool EnableAppendLog
115-
{
116-
get { return this.enableAppendLog; }
117-
set { this.enableAppendLog = value; }
118-
}
87+
public bool EnableAppendLog { get; set; }
11988

12089
/// <summary>
12190
/// Gets or sets the comma-delimited list of IP addresses that are approved to
@@ -125,20 +94,16 @@ public bool EnableAppendLog
12594
[Obsolete($"Use {nameof(AllowedIPAddresses)}")]
12695
public string WhitelistedIPAddresses
12796
{
128-
get { return this.allowedIPAddresses; }
129-
set { this.allowedIPAddresses = value; }
97+
get => this.AllowedIPAddresses;
98+
set => this.AllowedIPAddresses = value;
13099
}
131100

132101
/// <summary>
133102
/// Gets or sets the comma-delimited list of IP addresses that are approved to
134103
/// connect to this instance of the Chrome driver. Defaults to an empty string,
135104
/// which means only the local loopback address can connect.
136105
/// </summary>
137-
public string AllowedIPAddresses
138-
{
139-
get => this.allowedIPAddresses;
140-
set => this.allowedIPAddresses = value;
141-
}
106+
public string AllowedIPAddresses { get; set; } = string.Empty;
142107

143108
/// <summary>
144109
/// Gets the command-line arguments for the driver service.
@@ -148,49 +113,49 @@ protected override string CommandLineArguments
148113
get
149114
{
150115
StringBuilder argsBuilder = new StringBuilder(base.CommandLineArguments);
151-
if (this.adbPort > 0)
116+
if (this.AndroidDebugBridgePort > 0)
152117
{
153-
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --adb-port={0}", this.adbPort);
118+
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --adb-port={0}", this.AndroidDebugBridgePort);
154119
}
155120

156121
if (this.SuppressInitialDiagnosticInformation)
157122
{
158123
argsBuilder.Append(" --silent");
159124
}
160125

161-
if (this.disableBuildCheck)
126+
if (this.DisableBuildCheck)
162127
{
163128
argsBuilder.Append(" --disable-build-check");
164129
}
165130

166-
if (this.enableVerboseLogging)
131+
if (this.EnableVerboseLogging)
167132
{
168133
argsBuilder.Append(" --verbose");
169134
}
170135

171-
if (this.enableAppendLog)
136+
if (this.EnableAppendLog)
172137
{
173138
argsBuilder.Append(" --append-log");
174139
}
175140

176-
if (!string.IsNullOrEmpty(this.logPath))
141+
if (!string.IsNullOrEmpty(this.LogPath))
177142
{
178-
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --log-path=\"{0}\"", this.logPath);
143+
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --log-path=\"{0}\"", this.LogPath);
179144
}
180145

181-
if (!string.IsNullOrEmpty(this.urlPathPrefix))
146+
if (!string.IsNullOrEmpty(this.UrlPathPrefix))
182147
{
183-
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --url-base={0}", this.urlPathPrefix);
148+
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --url-base={0}", this.UrlPathPrefix);
184149
}
185150

186-
if (!string.IsNullOrEmpty(this.portServerAddress))
151+
if (!string.IsNullOrEmpty(this.PortServerAddress))
187152
{
188-
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --port-server={0}", this.portServerAddress);
153+
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --port-server={0}", this.PortServerAddress);
189154
}
190155

191-
if (!string.IsNullOrEmpty(this.allowedIPAddresses))
156+
if (!string.IsNullOrEmpty(this.AllowedIPAddresses))
192157
{
193-
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -allowed-ips={0}", this.allowedIPAddresses));
158+
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -allowed-ips={0}", this.AllowedIPAddresses));
194159
}
195160

196161
return argsBuilder.ToString();

0 commit comments

Comments
 (0)