diff --git a/dotnet/src/webdriver/ElementCoordinates.cs b/dotnet/src/webdriver/ElementCoordinates.cs index 79bcb902ae1bf..0db182201c740 100644 --- a/dotnet/src/webdriver/ElementCoordinates.cs +++ b/dotnet/src/webdriver/ElementCoordinates.cs @@ -21,14 +21,16 @@ using OpenQA.Selenium.Internal; using System; +#nullable enable + namespace OpenQA.Selenium { /// /// Defines the interface through which the user can discover where an element is on the screen. /// - internal class ElementCoordinates : ICoordinates + internal sealed class ElementCoordinates : ICoordinates { - private WebElement element; + private readonly WebElement element; /// /// Initializes a new instance of the class. @@ -36,32 +38,23 @@ internal class ElementCoordinates : ICoordinates /// The to be located. public ElementCoordinates(WebElement element) { - this.element = element; + this.element = element ?? throw new ArgumentNullException(nameof(element)); } /// /// Gets the location of an element in absolute screen coordinates. /// - public System.Drawing.Point LocationOnScreen - { - get { throw new NotImplementedException(); } - } + public System.Drawing.Point LocationOnScreen => throw new NotImplementedException(); /// /// Gets the location of an element relative to the origin of the view port. /// - public System.Drawing.Point LocationInViewport - { - get { return this.element.LocationOnScreenOnceScrolledIntoView; } - } + public System.Drawing.Point LocationInViewport => this.element.LocationOnScreenOnceScrolledIntoView; /// /// Gets the location of an element's position within the HTML DOM. /// - public System.Drawing.Point LocationInDom - { - get { return this.element.Location; } - } + public System.Drawing.Point LocationInDom => this.element.Location; /// /// Gets a locator providing a user-defined location for this element. @@ -70,17 +63,11 @@ public object AuxiliaryLocator { get { - IWebDriverObjectReference elementReference = this.element as IWebDriverObjectReference; - if (elementReference == null) - { - return null; - } - // Note that the OSS dialect of the wire protocol for the Actions API // uses the raw ID of the element, not an element reference. To use this, // extract the ID using the well-known key to the dictionary for element // references. - return elementReference.ObjectReferenceId; + return ((IWebDriverObjectReference)this.element).ObjectReferenceId; } } } diff --git a/dotnet/src/webdriver/Interactions/ActionSequence.cs b/dotnet/src/webdriver/Interactions/ActionSequence.cs index 2ad1576a084d5..40cf9d947ece4 100644 --- a/dotnet/src/webdriver/Interactions/ActionSequence.cs +++ b/dotnet/src/webdriver/Interactions/ActionSequence.cs @@ -22,6 +22,8 @@ using System.Globalization; using System.Text; +#nullable enable + namespace OpenQA.Selenium.Interactions { /// @@ -29,7 +31,7 @@ namespace OpenQA.Selenium.Interactions /// public class ActionSequence { - private List interactions = new List(); + private readonly List interactions = new List(); /// /// Initializes a new instance of the class. @@ -47,26 +49,18 @@ public ActionSequence(InputDevice device) /// the initial size of the sequence. public ActionSequence(InputDevice device, int initialSize) { - if (device == null) - { - throw new ArgumentNullException(nameof(device), "Input device cannot be null."); - } - - this.InputDevice = device; + this.InputDevice = device ?? throw new ArgumentNullException(nameof(device), "Input device cannot be null."); for (int i = 0; i < initialSize; i++) { - this.AddAction(new PauseInteraction(device, TimeSpan.Zero)); + this.AddAction(new PauseInteraction(this.InputDevice, TimeSpan.Zero)); } } /// /// Gets the count of actions in the sequence. /// - public int Count - { - get { return this.interactions.Count; } - } + public int Count => this.interactions.Count; /// /// Gets the input device for this Action sequence. diff --git a/dotnet/src/webdriver/Interactions/IAction.cs b/dotnet/src/webdriver/Interactions/IAction.cs index 57dfdcdd2fc72..69eaa55dd7517 100644 --- a/dotnet/src/webdriver/Interactions/IAction.cs +++ b/dotnet/src/webdriver/Interactions/IAction.cs @@ -17,6 +17,8 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium.Interactions { /// diff --git a/dotnet/src/webdriver/Interactions/ICoordinates.cs b/dotnet/src/webdriver/Interactions/ICoordinates.cs index 7f73d2167d3bc..f50271ed84819 100644 --- a/dotnet/src/webdriver/Interactions/ICoordinates.cs +++ b/dotnet/src/webdriver/Interactions/ICoordinates.cs @@ -19,6 +19,8 @@ using System.Drawing; +#nullable enable + namespace OpenQA.Selenium.Interactions.Internal { /// diff --git a/dotnet/src/webdriver/Interactions/InputDeviceKind.cs b/dotnet/src/webdriver/Interactions/InputDeviceKind.cs index 5c707ab72cb9b..b3232086124d0 100644 --- a/dotnet/src/webdriver/Interactions/InputDeviceKind.cs +++ b/dotnet/src/webdriver/Interactions/InputDeviceKind.cs @@ -17,6 +17,8 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium.Interactions { /// diff --git a/dotnet/src/webdriver/Interactions/Interaction.cs b/dotnet/src/webdriver/Interactions/Interaction.cs index 0b3aa8ff6effd..c7a0baea190fe 100644 --- a/dotnet/src/webdriver/Interactions/Interaction.cs +++ b/dotnet/src/webdriver/Interactions/Interaction.cs @@ -20,6 +20,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.Interactions { /// @@ -27,29 +29,19 @@ namespace OpenQA.Selenium.Interactions /// public abstract class Interaction { - private InputDevice sourceDevice; - /// /// Initializes a new instance of the class. /// /// The input device which performs this action. protected Interaction(InputDevice sourceDevice) { - if (sourceDevice == null) - { - throw new ArgumentNullException(nameof(sourceDevice), "Source device cannot be null"); - } - - this.sourceDevice = sourceDevice; + this.SourceDevice = sourceDevice ?? throw new ArgumentNullException(nameof(sourceDevice), "Source device cannot be null"); } /// /// Gets the device for which this action is intended. /// - public InputDevice SourceDevice - { - get { return this.sourceDevice; } - } + public InputDevice SourceDevice { get; } /// /// Returns a value for this action that can be transmitted across the wire to a remote end. @@ -65,7 +57,7 @@ public InputDevice SourceDevice /// otherwise, . public virtual bool IsValidFor(InputDeviceKind sourceDeviceKind) { - return this.sourceDevice.DeviceKind == sourceDeviceKind; + return this.SourceDevice.DeviceKind == sourceDeviceKind; } } } diff --git a/dotnet/src/webdriver/Interactions/PauseInteraction.cs b/dotnet/src/webdriver/Interactions/PauseInteraction.cs index 7d74731acb7cf..d571f2c30a1f0 100644 --- a/dotnet/src/webdriver/Interactions/PauseInteraction.cs +++ b/dotnet/src/webdriver/Interactions/PauseInteraction.cs @@ -21,6 +21,8 @@ using System.Collections.Generic; using System.Globalization; +#nullable enable + namespace OpenQA.Selenium.Interactions { /// @@ -28,7 +30,7 @@ namespace OpenQA.Selenium.Interactions /// internal class PauseInteraction : Interaction { - private TimeSpan duration = TimeSpan.Zero; + private readonly TimeSpan duration = TimeSpan.Zero; /// /// Initializes a new instance of the class. diff --git a/dotnet/src/webdriver/WebElement.cs b/dotnet/src/webdriver/WebElement.cs index 51cce73e1eb67..3d4a81338d61f 100644 --- a/dotnet/src/webdriver/WebElement.cs +++ b/dotnet/src/webdriver/WebElement.cs @@ -48,10 +48,11 @@ public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable, /// /// The instance that is driving this element. /// The ID value provided to identify the element. + /// If is . public WebElement(WebDriver parentDriver, string id) { this.driver = parentDriver; - this.elementId = id; + this.elementId = id ?? throw new ArgumentNullException(nameof(id)); } ///