Skip to content

Commit

Permalink
[dotnet] Annotate nullable reference types on input devices (#14804)
Browse files Browse the repository at this point in the history
* [dotnet] Annotate nullable reference types on input devices

* remove unnecessary `_`

* Use block-body methods in `InputDevice`

* Revert `WheelInputDevice.ConvertElement` and `PointerInputDevice.ConvertElement`

* Make methods always body-blocked

* Add null check to `CreatePointerMove`

* Add null check to `CreateWheelScroll`

* Do not demand for `PointerMoveInteraction.target` to be not-null
  • Loading branch information
RenderMichael authored Jan 24, 2025
1 parent 2383fac commit 78e1029
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 153 deletions.
16 changes: 7 additions & 9 deletions dotnet/src/webdriver/Interactions/InputDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,34 @@
using System.Collections.Generic;
using System.Globalization;

#nullable enable

namespace OpenQA.Selenium.Interactions
{
/// <summary>
/// Base class for all input devices for actions.
/// </summary>
public abstract class InputDevice
{
private string deviceName;

/// <summary>
/// Initializes a new instance of the <see cref="InputDevice"/> class.
/// </summary>
/// <param name="deviceName">The unique name of the input device represented by this class.</param>
/// <exception cref="ArgumentException">If <paramref name="deviceName"/> is <see langword="null"/> or <see cref="string.Empty"/>.</exception>
protected InputDevice(string deviceName)
{
if (string.IsNullOrEmpty(deviceName))
{
throw new ArgumentException("Device name must not be null or empty", nameof(deviceName));
}

this.deviceName = deviceName;
this.DeviceName = deviceName;
}

/// <summary>
/// Gets the unique name of this input device.
/// </summary>
public string DeviceName
{
get { return this.deviceName; }
}
public string DeviceName { get; }

/// <summary>
/// Gets the kind of device for this input device.
Expand Down Expand Up @@ -90,7 +88,7 @@ public Interaction CreatePause(TimeSpan duration)
/// <returns>A hash code for the current <see cref="InputDevice"/>.</returns>
public override int GetHashCode()
{
return this.deviceName.GetHashCode();
return this.DeviceName.GetHashCode();
}

/// <summary>
Expand All @@ -99,7 +97,7 @@ public override int GetHashCode()
/// <returns>A string that represents the current <see cref="InputDevice"/>.</returns>
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0} input device [name: {1}]", this.DeviceKind, this.deviceName);
return string.Format(CultureInfo.InvariantCulture, "{0} input device [name: {1}]", this.DeviceKind, this.DeviceName);
}
}
}
20 changes: 8 additions & 12 deletions dotnet/src/webdriver/Interactions/KeyInputDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System.Collections.Generic;
using System.Globalization;

#nullable enable

namespace OpenQA.Selenium.Interactions
{
/// <summary>
Expand All @@ -40,6 +42,7 @@ public KeyInputDevice()
/// Initializes a new instance of the <see cref="KeyInputDevice"/> class, given the device's name.
/// </summary>
/// <param name="deviceName">The unique name of this input device.</param>
/// <exception cref="ArgumentException">If <paramref name="deviceName"/> is <see langword="null"/> or <see cref="string.Empty"/>.</exception>
public KeyInputDevice(string deviceName)
: base(deviceName)
{
Expand All @@ -48,10 +51,7 @@ public KeyInputDevice(string deviceName)
/// <summary>
/// Gets the type of device for this input device.
/// </summary>
public override InputDeviceKind DeviceKind
{
get { return InputDeviceKind.Key; }
}
public override InputDeviceKind DeviceKind => InputDeviceKind.Key;

/// <summary>
/// Converts this input device into an object suitable for serializing across the wire.
Expand Down Expand Up @@ -115,27 +115,23 @@ public override string ToString()

private class TypingInteraction : Interaction
{
private string type;
private string value;
private readonly string type;

public TypingInteraction(InputDevice sourceDevice, string type, char codePoint)
: base(sourceDevice)
{
this.type = type;
this.value = codePoint.ToString();
this.Value = codePoint.ToString();
}

protected string Value
{
get { return this.value; }
}
protected string Value { get; }

public override Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> toReturn = new Dictionary<string, object>();

toReturn["type"] = this.type;
toReturn["value"] = this.value;
toReturn["value"] = this.Value;

return toReturn;
}
Expand Down
Loading

0 comments on commit 78e1029

Please sign in to comment.