Skip to content

Commit b66ceca

Browse files
[dotnet] Annotate nullable reference types on ActionBuilder (#14844)
* [dotnet] Annotate nullable reference types on `ActionBuilder` * remove unnecessary changes from `ActionBuilder`
1 parent 487b9a2 commit b66ceca

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

dotnet/src/webdriver/Interactions/ActionBuilder.cs

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

24+
#nullable enable
25+
2426
namespace OpenQA.Selenium.Interactions
2527
{
2628
/// <summary>
@@ -29,7 +31,7 @@ namespace OpenQA.Selenium.Interactions
2931
/// </summary>
3032
public class ActionBuilder
3133
{
32-
private Dictionary<InputDevice, ActionSequence> sequences = new Dictionary<InputDevice, ActionSequence>();
34+
private readonly Dictionary<InputDevice, ActionSequence> sequences = new Dictionary<InputDevice, ActionSequence>();
3335

3436
/// <summary>
3537
/// Adds an action to the built set of actions. Adding an action will
@@ -71,7 +73,7 @@ public IList<ActionSequence> ToActionSequenceList()
7173
/// </summary>
7274
public void ClearSequences()
7375
{
74-
this.sequences = new Dictionary<InputDevice, ActionSequence>();
76+
this.sequences.Clear();
7577
}
7678

7779
/// <summary>
@@ -94,8 +96,7 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
9496
List<InputDevice> usedDevices = new List<InputDevice>();
9597
foreach (Interaction interaction in interactionsToAdd)
9698
{
97-
InputDevice actionDevice = interaction.SourceDevice;
98-
if (usedDevices.Contains(actionDevice))
99+
if (usedDevices.Contains(interaction.SourceDevice))
99100
{
100101
throw new ArgumentException("You can only add one action per device for a single tick.");
101102
}
@@ -104,8 +105,9 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
104105
List<InputDevice> unusedDevices = new List<InputDevice>(this.sequences.Keys);
105106
foreach (Interaction interaction in interactionsToAdd)
106107
{
107-
ActionSequence sequence = this.FindSequence(interaction.SourceDevice);
108+
ActionSequence sequence = this.GetOrAddSequence(interaction.SourceDevice);
108109
sequence.AddAction(interaction);
110+
109111
unusedDevices.Remove(interaction.SourceDevice);
110112
}
111113

@@ -116,11 +118,11 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
116118
}
117119
}
118120

119-
private ActionSequence FindSequence(InputDevice device)
121+
private ActionSequence GetOrAddSequence(InputDevice device)
120122
{
121-
if (this.sequences.ContainsKey(device))
123+
if (this.sequences.TryGetValue(device, out ActionSequence? existingSequence))
122124
{
123-
return this.sequences[device];
125+
return existingSequence;
124126
}
125127

126128
int longestSequenceLength = 0;

0 commit comments

Comments
 (0)