21
21
using System . Collections . Generic ;
22
22
using System . Globalization ;
23
23
24
+ #nullable enable
25
+
24
26
namespace OpenQA . Selenium
25
27
{
26
28
/// <summary>
@@ -56,6 +58,7 @@ protected CommandInfoRepository()
56
58
/// </summary>
57
59
/// <param name="commandName">The name of the command to check.</param>
58
60
/// <returns><see langword="true"/> if the command name is defined</returns>
61
+ /// <exception cref="ArgumentNullException">If <paramref name="commandName"/> is <see langword="null"/>.</exception>
59
62
public bool IsCommandNameDefined ( string commandName )
60
63
{
61
64
return this . commandDictionary . ContainsKey ( commandName ) ;
@@ -66,7 +69,7 @@ public bool IsCommandNameDefined(string commandName)
66
69
/// </summary>
67
70
/// <param name="commandInfo">The <see cref="CommandInfo"/> object for which to find the command name.</param>
68
71
/// <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 )
70
73
{
71
74
foreach ( KeyValuePair < string , CommandInfo > pair in this . commandDictionary )
72
75
{
@@ -83,13 +86,13 @@ public string FindCommandName(CommandInfo commandInfo)
83
86
/// Gets the <see cref="HttpCommandInfo"/> for a <see cref="DriverCommand"/>.
84
87
/// </summary>
85
88
/// <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
88
91
{
89
- T toReturn = default ( T ) ;
90
- if ( this . commandDictionary . ContainsKey ( commandName ) )
92
+ T ? toReturn = default ;
93
+ if ( this . commandDictionary . TryGetValue ( commandName , out CommandInfo ? info ) )
91
94
{
92
- toReturn = this . commandDictionary [ commandName ] as T ;
95
+ toReturn = info as T ;
93
96
}
94
97
95
98
return toReturn ;
@@ -106,6 +109,12 @@ public T GetCommandInfo<T>(string commandName) where T : CommandInfo
106
109
/// This method will not overwrite existing commands for a specific name, and will return <see langword="false"/>
107
110
/// in that case.
108
111
/// </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>
109
118
public bool TryAddCommand < T > ( string commandName , T commandInfo ) where T : CommandInfo
110
119
{
111
120
if ( string . IsNullOrEmpty ( commandName ) )
0 commit comments