Skip to content

Commit 0983522

Browse files
[dotnet] Annotate nullability on devtools event args (#15134)
1 parent a080ec5 commit 0983522

31 files changed

+350
-191
lines changed

dotnet/src/webdriver/DevTools/AuthRequiredEventArgs.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,34 @@
1919

2020
using System;
2121

22+
#nullable enable
23+
2224
namespace OpenQA.Selenium.DevTools
2325
{
2426
/// <summary>
2527
/// Event arguments present when the AuthRequired event is raised.
2628
/// </summary>
2729
public class AuthRequiredEventArgs : EventArgs
2830
{
31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="AuthRequiredEventArgs"/> type.
33+
/// </summary>
34+
/// <param name="requestId">The request ID of the request raised the event.</param>
35+
/// <param name="uri">The URI for which the event is raised.</param>
36+
public AuthRequiredEventArgs(string requestId, string uri)
37+
{
38+
Uri = uri;
39+
RequestId = requestId;
40+
}
41+
2942
/// <summary>
3043
/// Gets the URI for which the event is raised.
3144
/// </summary>
32-
public string Uri { get; internal set; }
45+
public string Uri { get; }
3346

3447
/// <summary>
3548
/// Gets the request ID of the request raising the event.
3649
/// </summary>
37-
public string RequestId { get; internal set; }
50+
public string RequestId { get; }
3851
}
3952
}

dotnet/src/webdriver/DevTools/BindingCalledEventArgs.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,41 @@
1919

2020
using System;
2121

22+
#nullable enable
23+
2224
namespace OpenQA.Selenium.DevTools
2325
{
2426
/// <summary>
2527
/// Event arguments present when the BindingCalled event is raised.
2628
/// </summary>
2729
public class BindingCalledEventArgs : EventArgs
2830
{
31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="BindingCalledEventArgs"/> type.
33+
/// </summary>
34+
/// <param name="executionContextId">The execution ID of the call to the binding.</param>
35+
/// <param name="name">The name of the call to the binding.</param>
36+
/// <param name="payload">The payload of the call to the binding.</param>
37+
public BindingCalledEventArgs(long executionContextId, string name, string payload)
38+
{
39+
this.ExecutionContextId = executionContextId;
40+
this.Name = name;
41+
this.Payload = payload;
42+
}
43+
2944
/// <summary>
3045
/// Gets the execution context ID of the call to the binding.
3146
/// </summary>
32-
public long ExecutionContextId { get; internal set; }
47+
public long ExecutionContextId { get; }
3348

3449
/// <summary>
3550
/// Gets the name of the call to the binding.
3651
/// </summary>
37-
public string Name { get; internal set; }
52+
public string Name { get; }
3853

3954
/// <summary>
4055
/// Gets the payload of the call to the binding.
4156
/// </summary>
42-
public string Payload { get; internal set; }
57+
public string Payload { get; }
4358
}
4459
}

dotnet/src/webdriver/DevTools/CommandResponseExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// under the License.
1818
// </copyright>
1919

20+
#nullable enable
21+
2022
namespace OpenQA.Selenium.DevTools
2123
{
2224
/// <summary>
@@ -29,8 +31,8 @@ public static class ICommandResponseExtensions
2931
/// </summary>
3032
/// <typeparam name="TCommandResponse">The concrete implementation type of command response expected.</typeparam>
3133
/// <param name="response">The <see cref="ICommandResponse"/> object to convert to the implementation type</param>
32-
/// <returns>The concrete implementation of the command response.</returns>
33-
public static TCommandResponse GetResponse<TCommandResponse>(this ICommandResponse response)
34+
/// <returns>The concrete implementation of the command response, or <see langword="null"/> if <paramref name="response"/> is not the right type.</returns>
35+
public static TCommandResponse? GetResponse<TCommandResponse>(this ICommandResponse response)
3436
where TCommandResponse : class, ICommandResponse
3537
{
3638
return response as TCommandResponse;

dotnet/src/webdriver/DevTools/CommandResponseTypeMap.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
using System;
2121
using System.Collections.Generic;
22+
using System.Diagnostics.CodeAnalysis;
23+
24+
#nullable enable
2225

2326
namespace OpenQA.Selenium.DevTools
2427
{
@@ -34,8 +37,19 @@ public class CommandResponseTypeMap
3437
/// </summary>
3538
/// <param name="commandSettingsType">The type of command to add the mapping for.</param>
3639
/// <param name="commandResponseType">The type of response object corresponding to the command.</param>
40+
/// <exception cref="ArgumentNullException">If <paramref name="commandSettingsType"/> or <paramref name="commandResponseType"/> are <see langword="null"/>.</exception>
3741
public void AddCommandResponseType(Type commandSettingsType, Type commandResponseType)
3842
{
43+
if (commandSettingsType is null)
44+
{
45+
throw new ArgumentNullException(nameof(commandSettingsType));
46+
}
47+
48+
if (commandResponseType is null)
49+
{
50+
throw new ArgumentNullException(nameof(commandResponseType));
51+
}
52+
3953
if (!commandResponseTypeDictionary.ContainsKey(commandSettingsType))
4054
{
4155
commandResponseTypeDictionary.Add(commandSettingsType, commandResponseType);
@@ -48,7 +62,7 @@ public void AddCommandResponseType(Type commandSettingsType, Type commandRespons
4862
/// <typeparam name="T">The type of command for which to retrieve the response type.</typeparam>
4963
/// <param name="commandResponseType">The returned response type.</param>
5064
/// <returns><see langword="true"/> if the specified command type has a mapped response type; otherwise, <see langword="false"/>.</returns>
51-
public bool TryGetCommandResponseType<T>(out Type commandResponseType)
65+
public bool TryGetCommandResponseType<T>([NotNullWhen(true)] out Type? commandResponseType)
5266
where T : ICommand
5367
{
5468
return commandResponseTypeDictionary.TryGetValue(typeof(T), out commandResponseType);
@@ -60,7 +74,7 @@ public bool TryGetCommandResponseType<T>(out Type commandResponseType)
6074
/// <param name="command">The type of command for which to retrieve the response type.</param>
6175
/// <param name="commandResponseType">The returned response type.</param>
6276
/// <returns><see langword="true"/> if the specified command type has a mapped response type; otherwise, <see langword="false"/>.</returns>
63-
public bool TryGetCommandResponseType(ICommand command, out Type commandResponseType)
77+
public bool TryGetCommandResponseType(ICommand command, [NotNullWhen(true)] out Type? commandResponseType)
6478
{
6579
return commandResponseTypeDictionary.TryGetValue(command.GetType(), out commandResponseType);
6680
}

dotnet/src/webdriver/DevTools/ConsoleApiArgument.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,37 @@
1717
// under the License.
1818
// </copyright>
1919

20+
#nullable enable
21+
22+
using System;
23+
2024
namespace OpenQA.Selenium.DevTools
2125
{
2226
/// <summary>
2327
/// Represents information about a an argument in call to the browser's console API.
2428
/// </summary>
2529
public class ConsoleApiArgument
2630
{
31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="ConsoleApiArgument"/> type.
33+
/// </summary>
34+
/// <param name="type">The type of the argument in the call to the browser's console API.</param>
35+
/// <param name="value">The value of the argument in the call to the browser's console API.</param>
36+
/// <exception cref="ArgumentNullException">If <paramref name="type"/> is <see langword="null"/>.</exception>
37+
public ConsoleApiArgument(string type, string? value)
38+
{
39+
Type = type ?? throw new ArgumentNullException(nameof(type));
40+
Value = value;
41+
}
42+
2743
/// <summary>
2844
/// Gets the type of the argument in the call to the browser's console API.
2945
/// </summary>
30-
public string Type { get; internal set; }
46+
public string Type { get; }
3147

3248
/// <summary>
3349
/// Gets the value of the argument in the call to the browser's console API.
3450
/// </summary>
35-
public string Value { get; internal set; }
51+
public string? Value { get; }
3652
}
3753
}

dotnet/src/webdriver/DevTools/ConsoleApiCalledEventArgs.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,42 @@
2020
using System;
2121
using System.Collections.ObjectModel;
2222

23+
#nullable enable
24+
2325
namespace OpenQA.Selenium.DevTools
2426
{
2527
/// <summary>
2628
/// Event arguments present when the ConsoleApiCalled event is raised.
2729
/// </summary>
2830
public class ConsoleApiCalledEventArgs : EventArgs
2931
{
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="ConsoleApiCalledEventArgs"/> type.
34+
/// </summary>
35+
/// <param name="timestamp">The time stanp when the browser's console API is called.</param>
36+
/// <param name="type">The type of message when the browser's console API is called.</param>
37+
/// <param name="arguments">The arguments of the call to the browser's console API.</param>
38+
/// <exception cref="ArgumentNullException">If <paramref name="arguments"/> is <see langword="null"/>.</exception>
39+
public ConsoleApiCalledEventArgs(DateTime timestamp, string type, ReadOnlyCollection<ConsoleApiArgument> arguments)
40+
{
41+
Timestamp = timestamp;
42+
Type = type;
43+
Arguments = arguments ?? throw new ArgumentNullException(nameof(arguments));
44+
}
45+
3046
/// <summary>
3147
/// Gets the time stanp when the browser's console API is called.
3248
/// </summary>
33-
public DateTime Timestamp { get; internal set; }
49+
public DateTime Timestamp { get; }
3450

3551
/// <summary>
3652
/// Gets the type of message when the browser's console API is called.
3753
/// </summary>
38-
public string Type { get; internal set; }
54+
public string Type { get; }
3955

4056
/// <summary>
4157
/// Gets the arguments of the call to the browser's console API.
4258
/// </summary>
43-
public ReadOnlyCollection<ConsoleApiArgument> Arguments { get; internal set; }
59+
public ReadOnlyCollection<ConsoleApiArgument> Arguments { get; }
4460
}
4561
}

dotnet/src/webdriver/DevTools/DevToolsCommandData.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
2021
using System.Text.Json;
2122
using System.Text.Json.Nodes;
2223
using System.Text.Json.Serialization;
2324
using System.Threading;
2425

26+
#nullable enable
27+
2528
namespace OpenQA.Selenium.DevTools
2629
{
2730
/// <summary>
@@ -35,6 +38,7 @@ public class DevToolsCommandData
3538
/// <param name="commandId">The ID of the commmand execution.</param>
3639
/// <param name="commandName">The method name of the DevTools command.</param>
3740
/// <param name="commandParameters">The parameters of the DevTools command.</param>
41+
/// <exception cref="ArgumentNullException">If <paramref name="commandName"/> is <see langword="null"/>.</exception>
3842
public DevToolsCommandData(long commandId, string commandName, JsonNode commandParameters)
3943
: this(commandId, null, commandName, commandParameters)
4044
{
@@ -47,11 +51,12 @@ public DevToolsCommandData(long commandId, string commandName, JsonNode commandP
4751
/// <param name="sessionId">The session ID of the current command execution.</param>
4852
/// <param name="commandName">The method name of the DevTools command.</param>
4953
/// <param name="commandParameters">The parameters of the DevTools command.</param>
50-
public DevToolsCommandData(long commandId, string sessionId, string commandName, JsonNode commandParameters)
54+
/// <exception cref="ArgumentNullException">If <paramref name="commandName"/> is <see langword="null"/>.</exception>
55+
public DevToolsCommandData(long commandId, string? sessionId, string commandName, JsonNode commandParameters)
5156
{
5257
CommandId = commandId;
5358
SessionId = sessionId;
54-
CommandName = commandName;
59+
CommandName = commandName ?? throw new ArgumentNullException(nameof(commandName));
5560
CommandParameters = commandParameters;
5661
SyncEvent = new ManualResetEventSlim(false);
5762
}
@@ -61,7 +66,7 @@ public DevToolsCommandData(long commandId, string sessionId, string commandName,
6166
/// </summary>
6267
[JsonPropertyName("sessionId")]
6368
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
64-
public string SessionId { get; }
69+
public string? SessionId { get; }
6570

6671
/// <summary>
6772
/// Gets the numeric ID of the command execution.

dotnet/src/webdriver/DevTools/DevToolsEventData.cs

Lines changed: 5 additions & 2 deletions
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.DevTools
2325
{
2426
/// <summary>
@@ -31,10 +33,11 @@ public class DevToolsEventData
3133
/// </summary>
3234
/// <param name="eventArgsType">The type of the event args for the event to be raised.</param>
3335
/// <param name="invoker">The method that will be used to invoke the event.</param>
36+
/// <exception cref="ArgumentNullException">If<paramref name="eventArgsType"/> or <paramref name="invoker"/> is <see langword="null"/>.</exception>
3437
public DevToolsEventData(Type eventArgsType, Action<object> invoker)
3538
{
36-
EventArgsType = eventArgsType;
37-
EventInvoker = invoker;
39+
EventArgsType = eventArgsType ?? throw new ArgumentNullException(nameof(eventArgsType));
40+
EventInvoker = invoker ?? throw new ArgumentNullException(nameof(invoker));
3841
}
3942

4043
/// <summary>

dotnet/src/webdriver/DevTools/EntryAddedEventArgs.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,28 @@
1919

2020
using System;
2121

22+
#nullable enable
23+
2224
namespace OpenQA.Selenium.DevTools
2325
{
2426
/// <summary>
2527
/// Provides data for events relating to entries being added to the browser's log.
2628
/// </summary>
2729
public class EntryAddedEventArgs : EventArgs
2830
{
31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="EntryAddedEventArgs"/> type.
33+
/// </summary>
34+
/// <param name="entry">The entry added to the browser's log.</param>
35+
/// <exception cref="ArgumentNullException">If </exception>
36+
public EntryAddedEventArgs(LogEntry entry)
37+
{
38+
Entry = entry ?? throw new ArgumentNullException(nameof(entry));
39+
}
40+
2941
/// <summary>
3042
/// The entry added to the browser's log.
3143
/// </summary>
32-
public LogEntry Entry { get; set; }
44+
public LogEntry Entry { get; }
3345
}
3446
}

dotnet/src/webdriver/DevTools/LogEntry.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,34 @@
1717
// under the License.
1818
// </copyright>
1919

20+
#nullable enable
21+
2022
namespace OpenQA.Selenium.DevTools
2123
{
2224
/// <summary>
2325
/// Represents information about a log entry when the browser console is written to.
2426
/// </summary>
2527
public class LogEntry
2628
{
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="LogEntry"/> type.
31+
/// </summary>
32+
/// <param name="kind">The kind of message written to the log.</param>
33+
/// <param name="message">The text of the message written to the log.</param>
34+
public LogEntry(string kind, string message)
35+
{
36+
Kind = kind;
37+
Message = message;
38+
}
39+
2740
/// <summary>
2841
/// Gets the kind of message written to the log.
2942
/// </summary>
30-
public string Kind { get; internal set; }
43+
public string Kind { get; }
3144

3245
/// <summary>
3346
/// Gets the text of the message written to the log.
3447
/// </summary>
35-
public string Message { get; internal set; }
48+
public string Message { get; }
3649
}
3750
}

0 commit comments

Comments
 (0)