Skip to content

Commit 787cf6f

Browse files
[dotnet] Add nullability annotations to devtools domains (#15143)
* [dotnet] Add nullability annotations to devtools domains * Update dotnet/src/webdriver/DevTools/Json/JsonEnumMemberConverter.cs
1 parent 773f9e0 commit 787cf6f

12 files changed

+54
-29
lines changed

dotnet/src/webdriver/DevTools/DevToolsExtensionMethods.cs

+2
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>

dotnet/src/webdriver/DevTools/DevToolsOptions.cs

+2
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>

dotnet/src/webdriver/DevTools/DevToolsSessionDomains.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
// under the License.
1818
// </copyright>
1919

20+
#nullable enable
21+
2022
namespace OpenQA.Selenium.DevTools
2123
{
2224
/// <summary>
2325
/// Provides an abstract base class for version-specific domain implementations.
2426
/// </summary>
2527
public abstract class DevToolsSessionDomains
2628
{
27-
private CommandResponseTypeMap responseTypeMap = new CommandResponseTypeMap();
28-
2929
/// <summary>
3030
/// Initializes a new instance of the <see cref="DevToolsSessionDomains"/> class.
3131
/// </summary>
@@ -37,7 +37,7 @@ protected DevToolsSessionDomains()
3737
/// <summary>
3838
/// Gets the <see cref="CommandResponseTypeMap"/> containing information about the types returned by DevTools Protocol commands.,
3939
/// </summary>
40-
internal CommandResponseTypeMap ResponseTypeMap => this.responseTypeMap;
40+
internal CommandResponseTypeMap ResponseTypeMap { get; } = new CommandResponseTypeMap();
4141

4242
/// <summary>
4343
/// Populates the command response type map.

dotnet/src/webdriver/DevTools/DevToolsSessionEventReceivedEventArgs.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
using System.Text.Json;
2222
using System.Text.Json.Nodes;
2323

24+
#nullable enable
25+
2426
namespace OpenQA.Selenium.DevTools
2527
{
2628
/// <summary>
@@ -44,16 +46,16 @@ public DevToolsEventReceivedEventArgs(string domainName, string eventName, JsonE
4446
/// <summary>
4547
/// Gets the domain on which the event is to be raised.
4648
/// </summary>
47-
public string DomainName { get; private set; }
49+
public string DomainName { get; }
4850

4951
/// <summary>
5052
/// Gets the name of the event to be raised.
5153
/// </summary>
52-
public string EventName { get; private set; }
54+
public string EventName { get; }
5355

5456
/// <summary>
5557
/// Gets the data with which the event is to be raised.
5658
/// </summary>
57-
public JsonElement EventData { get; private set; }
59+
public JsonElement EventData { get; }
5860
}
5961
}

dotnet/src/webdriver/DevTools/DevToolsSessionLogMessageEventArgs.cs

+2
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>

dotnet/src/webdriver/DevTools/ExceptionThrownEventArgs.cs

+15-2
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
/// Provides data for events relating to JavaScript exception handling.
2628
/// </summary>
2729
public class ExceptionThrownEventArgs : EventArgs
2830
{
31+
/// <summary>
32+
/// Initializes new instance of the <see cref="ExceptionThrownEventArgs"/> type.
33+
/// </summary>
34+
/// <param name="timestamp">The time stamp of the exception.</param>
35+
/// <param name="message">The text of the exception.</param>
36+
public ExceptionThrownEventArgs(DateTime timestamp, string message)
37+
{
38+
Timestamp = timestamp;
39+
Message = message;
40+
}
41+
2942
/// <summary>
3043
/// Gets the time stamp of the exception.
3144
/// </summary>
32-
public DateTime Timestamp { get; internal set; }
45+
public DateTime Timestamp { get; }
3346

3447
/// <summary>
3548
/// Gets the text of the exception.
3649
/// </summary>
37-
public string Message { get; internal set; }
50+
public string Message { get; }
3851
}
3952
}

dotnet/src/webdriver/DevTools/Json/JsonEnumMemberConverter.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
using System.Text.Json;
2525
using System.Text.Json.Serialization;
2626

27+
#nullable enable
28+
2729
namespace OpenQA.Selenium.DevTools.Json
2830
{
2931
internal sealed class JsonEnumMemberConverter<TEnum> : JsonConverter<TEnum>
@@ -63,7 +65,7 @@ public JsonEnumMemberConverter()
6365

6466
public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
6567
{
66-
var stringValue = reader.GetString();
68+
var stringValue = reader.GetString() ?? throw new JsonException("Could not read an enum string from \"null\"");
6769

6870
if (_stringToEnum.TryGetValue(stringValue, out var enumValue))
6971
{

dotnet/src/webdriver/DevTools/ResponsePausedEventArgs.cs

+2
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>

dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
153153
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
154154
{
155155
// TODO: Collect stack trace elements
156-
var wrapped = new ExceptionThrownEventArgs()
157-
{
158-
Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
159-
Message = e.ExceptionDetails.Text
160-
};
156+
var wrapped = new ExceptionThrownEventArgs
157+
(
158+
timestamp: new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
159+
message: e.ExceptionDetails.Text
160+
);
161161

162162
this.OnExceptionThrown(wrapped);
163163
}

dotnet/src/webdriver/DevTools/v131/V131JavaScript.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
153153
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
154154
{
155155
// TODO: Collect stack trace elements
156-
var wrapped = new ExceptionThrownEventArgs()
157-
{
158-
Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
159-
Message = e.ExceptionDetails.Text
160-
};
156+
var wrapped = new ExceptionThrownEventArgs
157+
(
158+
timestamp: new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
159+
message: e.ExceptionDetails.Text
160+
);
161161

162162
this.OnExceptionThrown(wrapped);
163163
}

dotnet/src/webdriver/DevTools/v132/V132JavaScript.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
153153
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
154154
{
155155
// TODO: Collect stack trace elements
156-
var wrapped = new ExceptionThrownEventArgs()
157-
{
158-
Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
159-
Message = e.ExceptionDetails.Text
160-
};
156+
var wrapped = new ExceptionThrownEventArgs
157+
(
158+
timestamp: new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
159+
message: e.ExceptionDetails.Text
160+
);
161161

162162
this.OnExceptionThrown(wrapped);
163163
}

dotnet/src/webdriver/DevTools/v85/V85JavaScript.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
153153
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
154154
{
155155
// TODO: Collect stack trace elements
156-
var wrapped = new ExceptionThrownEventArgs()
157-
{
158-
Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
159-
Message = e.ExceptionDetails.Text
160-
};
156+
var wrapped = new ExceptionThrownEventArgs
157+
(
158+
timestamp: new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(e.Timestamp),
159+
message: e.ExceptionDetails.Text
160+
);
161161

162162
this.OnExceptionThrown(wrapped);
163163
}

0 commit comments

Comments
 (0)