2121using System . Collections . Generic ;
2222using System . Globalization ;
2323
24+ #nullable enable
25+
2426namespace 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,16 +86,15 @@ 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+ if ( this . commandDictionary . TryGetValue ( commandName , out CommandInfo ? info ) )
9193 {
92- toReturn = this . commandDictionary [ commandName ] as T ;
94+ return info as T ;
9395 }
9496
95- return toReturn ;
97+ return default ;
9698 }
9799
98100 /// <summary>
@@ -106,6 +108,12 @@ public T GetCommandInfo<T>(string commandName) where T : CommandInfo
106108 /// This method will not overwrite existing commands for a specific name, and will return <see langword="false"/>
107109 /// in that case.
108110 /// </remarks>
111+ /// <exception cref="ArgumentNullException">
112+ /// <para>If <paramref name="commandName"/> is <see langword="null"/> or <see cref="string.Empty"/>.</para>
113+ /// <para>-or-</para>
114+ /// <para>If <paramref name="commandInfo"/> is <see langword="null"/>.</para>
115+ /// </exception>
116+ /// <exception cref="ArgumentException">If <typeparamref name="T"/> is not a valid command type for this repository.</exception>
109117 public bool TryAddCommand < T > ( string commandName , T commandInfo ) where T : CommandInfo
110118 {
111119 if ( string . IsNullOrEmpty ( commandName ) )
0 commit comments