Skip to content

Commit 835ae4d

Browse files
RenderMichaelgryznar
authored andcommitted
[dotnet] Annotate nullable reference types on input devices (SeleniumHQ#14804)
* [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
1 parent 91a179b commit 835ae4d

File tree

4 files changed

+95
-153
lines changed

4 files changed

+95
-153
lines changed

dotnet/src/webdriver/Interactions/InputDevice.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,34 @@
2121
using System.Collections.Generic;
2222
using System.Globalization;
2323

24+
#nullable enable
25+
2426
namespace OpenQA.Selenium.Interactions
2527
{
2628
/// <summary>
2729
/// Base class for all input devices for actions.
2830
/// </summary>
2931
public abstract class InputDevice
3032
{
31-
private string deviceName;
32-
3333
/// <summary>
3434
/// Initializes a new instance of the <see cref="InputDevice"/> class.
3535
/// </summary>
3636
/// <param name="deviceName">The unique name of the input device represented by this class.</param>
37+
/// <exception cref="ArgumentException">If <paramref name="deviceName"/> is <see langword="null"/> or <see cref="string.Empty"/>.</exception>
3738
protected InputDevice(string deviceName)
3839
{
3940
if (string.IsNullOrEmpty(deviceName))
4041
{
4142
throw new ArgumentException("Device name must not be null or empty", nameof(deviceName));
4243
}
4344

44-
this.deviceName = deviceName;
45+
this.DeviceName = deviceName;
4546
}
4647

4748
/// <summary>
4849
/// Gets the unique name of this input device.
4950
/// </summary>
50-
public string DeviceName
51-
{
52-
get { return this.deviceName; }
53-
}
51+
public string DeviceName { get; }
5452

5553
/// <summary>
5654
/// Gets the kind of device for this input device.
@@ -90,7 +88,7 @@ public Interaction CreatePause(TimeSpan duration)
9088
/// <returns>A hash code for the current <see cref="InputDevice"/>.</returns>
9189
public override int GetHashCode()
9290
{
93-
return this.deviceName.GetHashCode();
91+
return this.DeviceName.GetHashCode();
9492
}
9593

9694
/// <summary>
@@ -99,7 +97,7 @@ public override int GetHashCode()
9997
/// <returns>A string that represents the current <see cref="InputDevice"/>.</returns>
10098
public override string ToString()
10199
{
102-
return string.Format(CultureInfo.InvariantCulture, "{0} input device [name: {1}]", this.DeviceKind, this.deviceName);
100+
return string.Format(CultureInfo.InvariantCulture, "{0} input device [name: {1}]", this.DeviceKind, this.DeviceName);
103101
}
104102
}
105103
}

dotnet/src/webdriver/Interactions/KeyInputDevice.cs

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

24+
#nullable enable
25+
2426
namespace OpenQA.Selenium.Interactions
2527
{
2628
/// <summary>
@@ -40,6 +42,7 @@ public KeyInputDevice()
4042
/// Initializes a new instance of the <see cref="KeyInputDevice"/> class, given the device's name.
4143
/// </summary>
4244
/// <param name="deviceName">The unique name of this input device.</param>
45+
/// <exception cref="ArgumentException">If <paramref name="deviceName"/> is <see langword="null"/> or <see cref="string.Empty"/>.</exception>
4346
public KeyInputDevice(string deviceName)
4447
: base(deviceName)
4548
{
@@ -48,10 +51,7 @@ public KeyInputDevice(string deviceName)
4851
/// <summary>
4952
/// Gets the type of device for this input device.
5053
/// </summary>
51-
public override InputDeviceKind DeviceKind
52-
{
53-
get { return InputDeviceKind.Key; }
54-
}
54+
public override InputDeviceKind DeviceKind => InputDeviceKind.Key;
5555

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

116116
private class TypingInteraction : Interaction
117117
{
118-
private string type;
119-
private string value;
118+
private readonly string type;
120119

121120
public TypingInteraction(InputDevice sourceDevice, string type, char codePoint)
122121
: base(sourceDevice)
123122
{
124123
this.type = type;
125-
this.value = codePoint.ToString();
124+
this.Value = codePoint.ToString();
126125
}
127126

128-
protected string Value
129-
{
130-
get { return this.value; }
131-
}
127+
protected string Value { get; }
132128

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

137133
toReturn["type"] = this.type;
138-
toReturn["value"] = this.value;
134+
toReturn["value"] = this.Value;
139135

140136
return toReturn;
141137
}

0 commit comments

Comments
 (0)