Skip to content

Commit 1aec5a8

Browse files
RenderMichaelsandeepsuryaprasad
authored andcommitted
[dotnet] Annotate nullability on command repository (SeleniumHQ#14888)
1 parent 9a7995d commit 1aec5a8

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

Diff for: dotnet/src/webdriver/CommandInfoRepository.cs

+15-6
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
2527
{
2628
/// <summary>
@@ -56,6 +58,7 @@ protected CommandInfoRepository()
5658
/// </summary>
5759
/// <param name="commandName">The name of the command to check.</param>
5860
/// <returns><see langword="true"/> if the command name is defined</returns>
61+
/// <exception cref="ArgumentNullException">If <paramref name="commandName"/> is <see langword="null"/>.</exception>
5962
public bool IsCommandNameDefined(string commandName)
6063
{
6164
return this.commandDictionary.ContainsKey(commandName);
@@ -66,7 +69,7 @@ public bool IsCommandNameDefined(string commandName)
6669
/// </summary>
6770
/// <param name="commandInfo">The <see cref="CommandInfo"/> object for which to find the command name.</param>
6871
/// <returns>The name of the command defined by the command info, or <see langword="null"/> if the command is not defined.</returns>
69-
public string FindCommandName(CommandInfo commandInfo)
72+
public string? FindCommandName(CommandInfo commandInfo)
7073
{
7174
foreach (KeyValuePair<string, CommandInfo> pair in this.commandDictionary)
7275
{
@@ -83,13 +86,13 @@ public string FindCommandName(CommandInfo commandInfo)
8386
/// Gets the <see cref="HttpCommandInfo"/> for a <see cref="DriverCommand"/>.
8487
/// </summary>
8588
/// <param name="commandName">The <see cref="DriverCommand"/> for which to get the information.</param>
86-
/// <returns>The <see cref="HttpCommandInfo"/> for the specified command.</returns>
87-
public T GetCommandInfo<T>(string commandName) where T : CommandInfo
89+
/// <returns>The <see cref="HttpCommandInfo"/> for the specified command, or <see langword="null"/> if not found or value is not <typeparamref name="T"/>.</returns>
90+
public T? GetCommandInfo<T>(string commandName) where T : CommandInfo
8891
{
89-
T toReturn = default(T);
90-
if (this.commandDictionary.ContainsKey(commandName))
92+
T? toReturn = default;
93+
if (this.commandDictionary.TryGetValue(commandName, out CommandInfo? info))
9194
{
92-
toReturn = this.commandDictionary[commandName] as T;
95+
toReturn = info as T;
9396
}
9497

9598
return toReturn;
@@ -106,6 +109,12 @@ public T GetCommandInfo<T>(string commandName) where T : CommandInfo
106109
/// This method will not overwrite existing commands for a specific name, and will return <see langword="false"/>
107110
/// in that case.
108111
/// </remarks>
112+
/// <exception cref="ArgumentNullException">
113+
/// <para>If <paramref name="commandName"/> is <see langword="null"/> or <see cref="string.Empty"/>.</para>
114+
/// <para>-or-</para>
115+
/// <para>If <paramref name="commandInfo"/> is <see langword="null"/>.</para>
116+
/// </exception>
117+
/// <exception cref="ArgumentException">If <typeparamref name="T"/> is not a valid command type for this repository.</exception>
109118
public bool TryAddCommand<T>(string commandName, T commandInfo) where T : CommandInfo
110119
{
111120
if (string.IsNullOrEmpty(commandName))

Diff for: dotnet/src/webdriver/Remote/W3CWireProtocolCommandInfoRepository.cs

+4-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
using System;
2121

22+
#nullable enable
23+
2224
namespace OpenQA.Selenium.Remote
2325
{
2426
/// <summary>
@@ -40,18 +42,12 @@ public W3CWireProtocolCommandInfoRepository()
4042
/// <summary>
4143
/// Gets the level of the W3C WebDriver specification that this repository supports.
4244
/// </summary>
43-
public override int SpecificationLevel
44-
{
45-
get { return 1; }
46-
}
45+
public override int SpecificationLevel => 1;
4746

4847
/// <summary>
4948
/// Gets the <see cref="Type"/> that is valid for this <see cref="CommandInfoRepository"/>
5049
/// </summary>
51-
protected override Type RepositoryCommandInfoType
52-
{
53-
get { return typeof(HttpCommandInfo); }
54-
}
50+
protected override Type RepositoryCommandInfoType => typeof(HttpCommandInfo);
5551

5652
/// <summary>
5753
/// Initializes the dictionary of commands for the CommandInfoRepository

0 commit comments

Comments
 (0)