Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Annotate nullability on command repository #14888

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions dotnet/src/webdriver/CommandInfoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System.Collections.Generic;
using System.Globalization;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
Expand Down Expand Up @@ -56,6 +58,7 @@ protected CommandInfoRepository()
/// </summary>
/// <param name="commandName">The name of the command to check.</param>
/// <returns><see langword="true"/> if the command name is defined</returns>
/// <exception cref="ArgumentNullException">If <paramref name="commandName"/> is <see langword="null"/>.</exception>
public bool IsCommandNameDefined(string commandName)
{
return this.commandDictionary.ContainsKey(commandName);
Expand All @@ -66,7 +69,7 @@ public bool IsCommandNameDefined(string commandName)
/// </summary>
/// <param name="commandInfo">The <see cref="CommandInfo"/> object for which to find the command name.</param>
/// <returns>The name of the command defined by the command info, or <see langword="null"/> if the command is not defined.</returns>
public string FindCommandName(CommandInfo commandInfo)
public string? FindCommandName(CommandInfo commandInfo)
{
foreach (KeyValuePair<string, CommandInfo> pair in this.commandDictionary)
{
Expand All @@ -83,13 +86,13 @@ public string FindCommandName(CommandInfo commandInfo)
/// Gets the <see cref="HttpCommandInfo"/> for a <see cref="DriverCommand"/>.
/// </summary>
/// <param name="commandName">The <see cref="DriverCommand"/> for which to get the information.</param>
/// <returns>The <see cref="HttpCommandInfo"/> for the specified command.</returns>
public T GetCommandInfo<T>(string commandName) where T : CommandInfo
/// <returns>The <see cref="HttpCommandInfo"/> for the specified command, or <see langword="null"/> if not found or value is not <typeparamref name="T"/>.</returns>
public T? GetCommandInfo<T>(string commandName) where T : CommandInfo
{
T toReturn = default(T);
if (this.commandDictionary.ContainsKey(commandName))
T? toReturn = default;
if (this.commandDictionary.TryGetValue(commandName, out CommandInfo? info))
{
toReturn = this.commandDictionary[commandName] as T;
toReturn = info as T;
}

return toReturn;
Expand All @@ -106,6 +109,12 @@ public T GetCommandInfo<T>(string commandName) where T : CommandInfo
/// This method will not overwrite existing commands for a specific name, and will return <see langword="false"/>
/// in that case.
/// </remarks>
/// <exception cref="ArgumentNullException">
/// <para>If <paramref name="commandName"/> is <see langword="null"/> or <see cref="string.Empty"/>.</para>
/// <para>-or-</para>
/// <para>If <paramref name="commandInfo"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">If <typeparamref name="T"/> is not a valid command type for this repository.</exception>
nvborisenko marked this conversation as resolved.
Show resolved Hide resolved
public bool TryAddCommand<T>(string commandName, T commandInfo) where T : CommandInfo
{
if (string.IsNullOrEmpty(commandName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

using System;

#nullable enable

namespace OpenQA.Selenium.Remote
{
/// <summary>
Expand All @@ -40,18 +42,12 @@ public W3CWireProtocolCommandInfoRepository()
/// <summary>
/// Gets the level of the W3C WebDriver specification that this repository supports.
/// </summary>
public override int SpecificationLevel
{
get { return 1; }
}
public override int SpecificationLevel => 1;

/// <summary>
/// Gets the <see cref="Type"/> that is valid for this <see cref="CommandInfoRepository"/>
/// </summary>
protected override Type RepositoryCommandInfoType
{
get { return typeof(HttpCommandInfo); }
}
protected override Type RepositoryCommandInfoType => typeof(HttpCommandInfo);

/// <summary>
/// Initializes the dictionary of commands for the CommandInfoRepository
Expand Down
Loading