Skip to content

Commit fc463fd

Browse files
[dotnet] Start adding nullable reference type annotations to the Support package (#14779)
* [dotnet] All nullable reference type annotations to support (part 1) * minimize diffs * Add exception XMLDoc to `PopupWindowFinder` * Make some updates to `SelectElement` * [dotnet] Update bazel build to recognize Support as nullable-annotated and langversion * fix `nullable` variable name
1 parent cc814a8 commit fc463fd

22 files changed

+185
-287
lines changed

dotnet/src/support/BUILD.bazel

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ csharp_library(
3535
"UI/*.cs",
3636
]) + [":assembly-info"],
3737
out = "WebDriver.Support",
38+
langversion = "12.0",
39+
nullable = "annotations",
3840
target_frameworks = [
3941
"netstandard2.0",
4042
],
@@ -74,6 +76,8 @@ csharp_library(
7476
]) + [":assembly-info"],
7577
out = "WebDriver.Support.StrongNamed",
7678
keyfile = "//dotnet:WebDriver.snk",
79+
langversion = "12.0",
80+
nullable = "annotations",
7781
target_frameworks = [
7882
"netstandard2.0",
7983
],

dotnet/src/support/Events/FindElementEventArgs.cs

+12-23
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ namespace OpenQA.Selenium.Support.Events
2626
/// </summary>
2727
public class FindElementEventArgs : EventArgs
2828
{
29-
private IWebDriver driver;
30-
private IWebElement element;
31-
private By method;
32-
3329
/// <summary>
3430
/// Initializes a new instance of the <see cref="FindElementEventArgs"/> class.
3531
/// </summary>
3632
/// <param name="driver">The WebDriver instance used in finding elements.</param>
37-
/// <param name="method">The <see cref="By"/> object containing the method used to find elements</param>
33+
/// <param name="method">The <see cref="By"/> object containing the method used to find elements.</param>
34+
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="method"/> are <see langword="null"/>.</exception>
3835
public FindElementEventArgs(IWebDriver driver, By method)
3936
: this(driver, null, method)
4037
{
@@ -44,37 +41,29 @@ public FindElementEventArgs(IWebDriver driver, By method)
4441
/// Initializes a new instance of the <see cref="FindElementEventArgs"/> class.
4542
/// </summary>
4643
/// <param name="driver">The WebDriver instance used in finding elements.</param>
47-
/// <param name="element">The parent element used as the context for the search.</param>
44+
/// <param name="element">The parent element used as the context for the search, or <see langword="null"/> if none exists.</param>
4845
/// <param name="method">The <see cref="By"/> object containing the method used to find elements.</param>
49-
public FindElementEventArgs(IWebDriver driver, IWebElement element, By method)
46+
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="method"/> are <see langword="null"/>.</exception>
47+
public FindElementEventArgs(IWebDriver driver, IWebElement? element, By method)
5048
{
51-
this.driver = driver;
52-
this.element = element;
53-
this.method = method;
49+
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
50+
this.Element = element;
51+
this.FindMethod = method ?? throw new ArgumentNullException(nameof(method));
5452
}
5553

5654
/// <summary>
5755
/// Gets the WebDriver instance used in finding elements.
5856
/// </summary>
59-
public IWebDriver Driver
60-
{
61-
get { return this.driver; }
62-
}
57+
public IWebDriver Driver { get; }
6358

6459
/// <summary>
65-
/// Gets the parent element used as the context for the search.
60+
/// Gets the parent element used as the context for the search, or <see langword="null"/> if no element is associated.
6661
/// </summary>
67-
public IWebElement Element
68-
{
69-
get { return this.element; }
70-
}
62+
public IWebElement? Element { get; }
7163

7264
/// <summary>
7365
/// Gets the <see cref="By"/> object containing the method used to find elements.
7466
/// </summary>
75-
public By FindMethod
76-
{
77-
get { return this.method; }
78-
}
67+
public By FindMethod { get; }
7968
}
8069
}

dotnet/src/support/Events/GetShadowRootEventArgs.cs

+5-13
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,26 @@ namespace OpenQA.Selenium.Support.Events
2626
/// </summary>
2727
public class GetShadowRootEventArgs : EventArgs
2828
{
29-
private IWebDriver driver;
30-
private ISearchContext searchContext;
31-
3229
/// <summary>
3330
/// Initializes a new instance of the <see cref="GetShadowRootEventArgs"/> class.
3431
/// </summary>
3532
/// <param name="driver">The WebDriver instance used in the current context.</param>
3633
/// <param name="searchContext">The parent searc context used as the context for getting shadow root.</param>
34+
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="searchContext"/> are <see langword="null"/>.</exception>
3735
public GetShadowRootEventArgs(IWebDriver driver, ISearchContext searchContext)
3836
{
39-
this.driver = driver;
40-
this.searchContext = searchContext;
37+
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
38+
this.SearchContext = searchContext ?? throw new ArgumentNullException(nameof(searchContext));
4139
}
4240

4341
/// <summary>
4442
/// Gets the WebDriver instance used in the current context.
4543
/// </summary>
46-
public IWebDriver Driver
47-
{
48-
get { return this.driver; }
49-
}
44+
public IWebDriver Driver { get; }
5045

5146
/// <summary>
5247
/// Gets the parent search context used as the context for getting shadow root.
5348
/// </summary>
54-
public ISearchContext SearchContext
55-
{
56-
get { return this.searchContext; }
57-
}
49+
public ISearchContext SearchContext { get; }
5850
}
5951
}

dotnet/src/support/Events/WebDriverExceptionEventArgs.cs

+6-14
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,26 @@ namespace OpenQA.Selenium.Support.Events
2626
/// </summary>
2727
public class WebDriverExceptionEventArgs : EventArgs
2828
{
29-
private Exception thrownException;
30-
private IWebDriver driver;
31-
3229
/// <summary>
3330
/// Initializes a new instance of the <see cref="WebDriverExceptionEventArgs"/> class.
3431
/// </summary>
3532
/// <param name="driver">The WebDriver instance throwing the exception.</param>
3633
/// <param name="thrownException">The exception thrown by the driver.</param>
34+
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="thrownException"/> are <see langword="null"/>.</exception>
3735
public WebDriverExceptionEventArgs(IWebDriver driver, Exception thrownException)
3836
{
39-
this.driver = driver;
40-
this.thrownException = thrownException;
37+
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
38+
this.ThrownException = thrownException ?? throw new ArgumentNullException(nameof(thrownException));
4139
}
4240

4341
/// <summary>
4442
/// Gets the exception thrown by the driver.
4543
/// </summary>
46-
public Exception ThrownException
47-
{
48-
get { return this.thrownException; }
49-
}
44+
public Exception ThrownException { get; }
5045

5146
/// <summary>
52-
/// Gets the WebDriver instance .
47+
/// Gets the WebDriver instance.
5348
/// </summary>
54-
public IWebDriver Driver
55-
{
56-
get { return this.driver; }
57-
}
49+
public IWebDriver Driver { get; }
5850
}
5951
}

dotnet/src/support/Events/WebDriverNavigationEventArgs.cs

+9-16
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ namespace OpenQA.Selenium.Support.Events
2626
/// </summary>
2727
public class WebDriverNavigationEventArgs : EventArgs
2828
{
29-
private string url;
30-
private IWebDriver driver;
31-
3229
/// <summary>
3330
/// Initializes a new instance of the <see cref="WebDriverNavigationEventArgs"/> class.
3431
/// </summary>
3532
/// <param name="driver">The WebDriver instance used in navigation.</param>
33+
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> is <see langword="null"/>.</exception>
3634
public WebDriverNavigationEventArgs(IWebDriver driver)
3735
: this(driver, null)
3836
{
@@ -42,27 +40,22 @@ public WebDriverNavigationEventArgs(IWebDriver driver)
4240
/// Initializes a new instance of the <see cref="WebDriverNavigationEventArgs"/> class.
4341
/// </summary>
4442
/// <param name="driver">The WebDriver instance used in navigation.</param>
45-
/// <param name="url">The URL navigated to by the driver.</param>
46-
public WebDriverNavigationEventArgs(IWebDriver driver, string url)
43+
/// <param name="url">The URL navigated to by the driver, or <see langword="null"/> if none exists.</param>
44+
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> is <see langword="null"/>.</exception>
45+
public WebDriverNavigationEventArgs(IWebDriver driver, string? url)
4746
{
48-
this.url = url;
49-
this.driver = driver;
47+
this.Url = url;
48+
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
5049
}
5150

5251
/// <summary>
53-
/// Gets the URL navigated to by the driver.
52+
/// Gets the URL navigated to by the driver, or <see langword="null"/> if no URL could be determined.
5453
/// </summary>
55-
public string Url
56-
{
57-
get { return this.url; }
58-
}
54+
public string? Url { get; }
5955

6056
/// <summary>
6157
/// Gets the WebDriver instance used in navigation.
6258
/// </summary>
63-
public IWebDriver Driver
64-
{
65-
get { return this.driver; }
66-
}
59+
public IWebDriver Driver { get; }
6760
}
6861
}

dotnet/src/support/Events/WebDriverScriptEventArgs.cs

+5-13
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,26 @@ namespace OpenQA.Selenium.Support.Events
2626
/// </summary>
2727
public class WebDriverScriptEventArgs : EventArgs
2828
{
29-
private IWebDriver driver;
30-
private string script;
31-
3229
/// <summary>
3330
/// Initializes a new instance of the <see cref="WebDriverScriptEventArgs"/> class.
3431
/// </summary>
3532
/// <param name="driver">The WebDriver instance used to execute the script.</param>
3633
/// <param name="script">The script executed by the driver.</param>
34+
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="script"/> are <see langword="null"/>.</exception>
3735
public WebDriverScriptEventArgs(IWebDriver driver, string script)
3836
{
39-
this.driver = driver;
40-
this.script = script;
37+
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
38+
this.Script = script ?? throw new ArgumentNullException(nameof(script));
4139
}
4240

4341
/// <summary>
4442
/// Gets the WebDriver instance used to execute the script.
4543
/// </summary>
46-
public IWebDriver Driver
47-
{
48-
get { return this.driver; }
49-
}
44+
public IWebDriver Driver { get; }
5045

5146
/// <summary>
5247
/// Gets the script executed by the driver.
5348
/// </summary>
54-
public string Script
55-
{
56-
get { return this.script; }
57-
}
49+
public string Script { get; }
5850
}
5951
}

dotnet/src/support/Events/WebElementEventArgs.cs

+5-13
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,26 @@ namespace OpenQA.Selenium.Support.Events
2626
/// </summary>
2727
public class WebElementEventArgs : EventArgs
2828
{
29-
private IWebDriver driver;
30-
private IWebElement element;
31-
3229
/// <summary>
3330
/// Initializes a new instance of the <see cref="WebElementEventArgs"/> class.
3431
/// </summary>
3532
/// <param name="driver">The WebDriver instance used for the action.</param>
3633
/// <param name="element">The element used for the action.</param>
34+
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="element"/> are <see langword="null"/>.</exception>
3735
public WebElementEventArgs(IWebDriver driver, IWebElement element)
3836
{
39-
this.driver = driver;
40-
this.element = element;
37+
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
38+
this.Element = element ?? throw new ArgumentNullException(nameof(element));
4139
}
4240

4341
/// <summary>
4442
/// Gets the WebDriver instance used for the action.
4543
/// </summary>
46-
public IWebDriver Driver
47-
{
48-
get { return this.driver; }
49-
}
44+
public IWebDriver Driver { get; }
5045

5146
/// <summary>
5247
/// Gets the element used for the action.
5348
/// </summary>
54-
public IWebElement Element
55-
{
56-
get { return this.element; }
57-
}
49+
public IWebElement Element { get; }
5850
}
5951
}

dotnet/src/support/Events/WebElementValueEventArgs.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
2022
namespace OpenQA.Selenium.Support.Events
2123
{
2224
/// <summary>
@@ -30,15 +32,16 @@ public class WebElementValueEventArgs : WebElementEventArgs
3032
/// <param name="driver">The WebDriver instance used for the action.</param>
3133
/// <param name="element">The element used for the action.</param>
3234
/// <param name="value">The new value for the element.</param>
33-
public WebElementValueEventArgs(IWebDriver driver, IWebElement element, string value)
35+
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="element"/> are <see langword="null"/>.</exception>
36+
public WebElementValueEventArgs(IWebDriver driver, IWebElement element, string? value)
3437
: base(driver, element)
3538
{
3639
this.Value = value;
3740
}
3841

3942
/// <summary>
40-
/// Gets the Value that is written to the element
43+
/// Gets the Value that is written to the element.
4144
/// </summary>
42-
public string Value { get; private set; }
45+
public string? Value { get; }
4346
}
4447
}

0 commit comments

Comments
 (0)