Skip to content

Commit 2515ebc

Browse files
authored
chore: enable #nullable iteration 4 (#3175)
1 parent d0f2745 commit 2515ebc

28 files changed

+210
-173
lines changed

src/Playwright/API/Generated/IWebSocketRoute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public partial interface IWebSocketRoute
170170
/// code</a> and an optional <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close#reason">close
171171
/// reason</a>.
172172
/// </param>
173-
void OnClose(Action<int?, string> handler);
173+
void OnClose(Action<int?, string?> handler);
174174

175175
/// <summary>
176176
/// <para>

src/Playwright/Core/BrowserContextEvent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
#nullable enable
2425

2526
namespace Microsoft.Playwright.Core;
2627

src/Playwright/Core/Clock.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
#nullable enable
2425

2526
using System;
2627
using System.Collections.Generic;
@@ -30,13 +31,13 @@ namespace Microsoft.Playwright.Core;
3031

3132
internal class Clock(BrowserContext browserContext) : IClock
3233
{
33-
public async Task InstallAsync(ClockInstallOptions options = null)
34+
public async Task InstallAsync(ClockInstallOptions? options = null)
3435
{
3536
options ??= new();
36-
Dictionary<string, object> args = null;
37-
if ((options.Time ?? options.TimeString) != null)
37+
Dictionary<string, object?> args = null!;
38+
if ((options.TimeString ?? options.Time) != null)
3839
{
39-
args = ParseTime(options.Time ?? options.TimeString);
40+
args = ParseTime(options.TimeString ?? options.Time);
4041
}
4142
else if (options.TimeDate != null)
4243
{
@@ -45,16 +46,16 @@ public async Task InstallAsync(ClockInstallOptions options = null)
4546
await browserContext.SendMessageToServerAsync("clockInstall", args).ConfigureAwait(false);
4647
}
4748

48-
private static Dictionary<string, object> ParseTime(string timeString)
49+
private static Dictionary<string, object?> ParseTime(string? timeString)
4950
=> new() { ["timeString"] = timeString };
5051

51-
private static Dictionary<string, object> ParseTime(DateTime? timeDate)
52-
=> new() { ["timeNumber"] = ((DateTimeOffset)timeDate.Value).ToUnixTimeMilliseconds() };
52+
private static Dictionary<string, object?> ParseTime(DateTime? timeDate)
53+
=> new() { ["timeNumber"] = ((DateTimeOffset?)timeDate)?.ToUnixTimeMilliseconds() };
5354

54-
private Dictionary<string, object> ParseTicks(long ticks)
55+
private Dictionary<string, object?> ParseTicks(long ticks)
5556
=> new() { ["ticksNumber"] = ticks };
5657

57-
private Dictionary<string, object> ParseTicks(string ticks)
58+
private Dictionary<string, object?> ParseTicks(string ticks)
5859
=> new() { ["ticksString"] = ticks };
5960

6061
public Task FastForwardAsync(long ticks)

src/Playwright/Core/ConsoleMessage.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
#nullable enable
2425

2526
using System.Collections.Generic;
2627
using System.Linq;
@@ -55,17 +56,17 @@ internal ConsoleMessage(BrowserContextConsoleEvent @event)
5556
internal class BrowserContextConsoleEvent
5657
{
5758
[JsonPropertyName("page")]
58-
public Page Page { get; set; }
59+
public Page Page { get; set; } = null!;
5960

6061
[JsonPropertyName("type")]
61-
public string Type { get; set; }
62+
public string Type { get; set; } = null!;
6263

6364
[JsonPropertyName("text")]
64-
public string Text { get; set; }
65+
public string Text { get; set; } = null!;
6566

6667
[JsonPropertyName("args")]
67-
public List<JSHandle> Args { get; set; }
68+
public List<JSHandle> Args { get; set; } = null!;
6869

6970
[JsonPropertyName("location")]
70-
public ConsoleMessageLocation Location { get; set; }
71+
public ConsoleMessageLocation Location { get; set; } = null!;
7172
}

src/Playwright/Core/Download.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
#nullable enable
2425

2526
using System.Threading.Tasks;
2627

@@ -51,7 +52,7 @@ internal Download(IPage page, string url, string suggestedFilename, Artifact art
5152

5253
public Task<string> PathAsync() => _artifact.PathAfterFinishedAsync();
5354

54-
public Task<string> FailureAsync() => _artifact.FailureAsync();
55+
public Task<string?> FailureAsync() => _artifact.FailureAsync();
5556

5657
public Task DeleteAsync() => _artifact.DeleteAsync();
5758

src/Playwright/Core/FileChooser.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
#nullable enable
2425
using System.Collections.Generic;
2526
using System.Threading.Tasks;
2627

@@ -53,19 +54,19 @@ public FileChooser(IPage page, ElementHandle element, bool multiple)
5354

5455
public bool IsMultiple { get; set; }
5556

56-
public Task SetFilesAsync(string files, FileChooserSetFilesOptions options = default)
57+
public Task SetFilesAsync(string files, FileChooserSetFilesOptions? options = default)
5758
=> ElementImpl.SetInputFilesAsync(files, Map(options));
5859

59-
public Task SetFilesAsync(IEnumerable<string> files, FileChooserSetFilesOptions options = default)
60+
public Task SetFilesAsync(IEnumerable<string> files, FileChooserSetFilesOptions? options = default)
6061
=> ElementImpl.SetInputFilesAsync(files, Map(options));
6162

62-
public Task SetFilesAsync(FilePayload files, FileChooserSetFilesOptions options = default)
63+
public Task SetFilesAsync(FilePayload files, FileChooserSetFilesOptions? options = default)
6364
=> ElementImpl.SetInputFilesAsync(files, Map(options));
6465

65-
public Task SetFilesAsync(IEnumerable<FilePayload> files, FileChooserSetFilesOptions options = default)
66+
public Task SetFilesAsync(IEnumerable<FilePayload> files, FileChooserSetFilesOptions? options = default)
6667
=> ElementImpl.SetInputFilesAsync(files, Map(options));
6768

68-
private ElementHandleSetInputFilesOptions Map(FileChooserSetFilesOptions options)
69+
private ElementHandleSetInputFilesOptions? Map(FileChooserSetFilesOptions? options)
6970
{
7071
if (options == null)
7172
{

src/Playwright/Core/FormData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
#nullable enable
2425

2526
using System;
2627
using System.Collections.Generic;

src/Playwright/Core/FrameLocator.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
* SOFTWARE.
2525
*/
26+
#nullable enable
2627

2728
using System.Text.RegularExpressions;
2829

@@ -45,25 +46,25 @@ public FrameLocator(Frame parent, string selector)
4546

4647
public ILocator Owner => new Locator(_frame, _frameSelector);
4748

48-
ILocator IFrameLocator.GetByAltText(string text, FrameLocatorGetByAltTextOptions options)
49+
ILocator IFrameLocator.GetByAltText(string text, FrameLocatorGetByAltTextOptions? options)
4950
=> Locator(Core.Locator.GetByAltTextSelector(text, options?.Exact));
5051

51-
public ILocator GetByAltText(Regex text, FrameLocatorGetByAltTextOptions options = null)
52+
public ILocator GetByAltText(Regex? text, FrameLocatorGetByAltTextOptions? options = null)
5253
=> Locator(Core.Locator.GetByAltTextSelector(text, options?.Exact));
5354

54-
public ILocator GetByLabel(string text, FrameLocatorGetByLabelOptions options = null)
55+
public ILocator GetByLabel(string text, FrameLocatorGetByLabelOptions? options = null)
5556
=> Locator(Core.Locator.GetByLabelSelector(text, options?.Exact));
5657

57-
public ILocator GetByLabel(Regex text, FrameLocatorGetByLabelOptions options = null)
58+
public ILocator GetByLabel(Regex text, FrameLocatorGetByLabelOptions? options = null)
5859
=> Locator(Core.Locator.GetByLabelSelector(text, options?.Exact));
5960

60-
public ILocator GetByPlaceholder(string text, FrameLocatorGetByPlaceholderOptions options = null)
61+
public ILocator GetByPlaceholder(string text, FrameLocatorGetByPlaceholderOptions? options = null)
6162
=> Locator(Core.Locator.GetByPlaceholderSelector(text, options?.Exact));
6263

63-
public ILocator GetByPlaceholder(Regex text, FrameLocatorGetByPlaceholderOptions options = null)
64+
public ILocator GetByPlaceholder(Regex text, FrameLocatorGetByPlaceholderOptions? options = null)
6465
=> Locator(Core.Locator.GetByPlaceholderSelector(text, options?.Exact));
6566

66-
public ILocator GetByRole(AriaRole role, FrameLocatorGetByRoleOptions options = null)
67+
public ILocator GetByRole(AriaRole role, FrameLocatorGetByRoleOptions? options = null)
6768
=> Locator(Core.Locator.GetByRoleSelector(role, new(options)));
6869

6970
public ILocator GetByTestId(string testId)
@@ -72,21 +73,21 @@ public ILocator GetByTestId(string testId)
7273
public ILocator GetByTestId(Regex testId)
7374
=> Locator(Core.Locator.GetByTestIdSelector(Core.Locator.TestIdAttributeName(), testId));
7475

75-
public ILocator GetByText(string text, FrameLocatorGetByTextOptions options = null)
76+
public ILocator GetByText(string text, FrameLocatorGetByTextOptions? options = null)
7677
=> Locator(Core.Locator.GetByTextSelector(text, options?.Exact));
7778

78-
public ILocator GetByText(Regex text, FrameLocatorGetByTextOptions options = null)
79+
public ILocator GetByText(Regex text, FrameLocatorGetByTextOptions? options = null)
7980
=> Locator(Core.Locator.GetByTextSelector(text, options?.Exact));
8081

81-
public ILocator GetByTitle(string text, FrameLocatorGetByTitleOptions options = null)
82+
public ILocator GetByTitle(string text, FrameLocatorGetByTitleOptions? options = null)
8283
=> Locator(Core.Locator.GetByTitleSelector(text, options?.Exact));
8384

84-
public ILocator GetByTitle(Regex text, FrameLocatorGetByTitleOptions options = null)
85+
public ILocator GetByTitle(Regex text, FrameLocatorGetByTitleOptions? options = null)
8586
=> Locator(Core.Locator.GetByTitleSelector(text, options?.Exact));
8687

8788
IFrameLocator IFrameLocator.FrameLocator(string selector) => new FrameLocator(_frame, $"{_frameSelector} >> internal:control=enter-frame >> {selector}");
8889

89-
public ILocator Locator(string selector, FrameLocatorLocatorOptions options = null)
90+
public ILocator Locator(string selector, FrameLocatorLocatorOptions? options = null)
9091
=> new Locator(_frame, $"{_frameSelector} >> internal:control=enter-frame >> {selector}", new()
9192
{
9293
Has = options?.Has,
@@ -99,7 +100,7 @@ public ILocator Locator(string selector, FrameLocatorLocatorOptions options = nu
99100
HasNotTextString = options?.HasNotTextString,
100101
});
101102

102-
public ILocator Locator(ILocator locator, FrameLocatorLocatorOptions options = null)
103+
public ILocator Locator(ILocator locator, FrameLocatorLocatorOptions? options = null)
103104
{
104105
var locatorImpl = (Locator)locator;
105106
if (locatorImpl._frame != _frame)

src/Playwright/Core/JSHandle.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
#nullable enable
2425

2526
using System;
2627
using System.Collections.Generic;
@@ -43,33 +44,33 @@ internal JSHandle(ChannelOwner parent, string guid, JSHandleInitializer initiali
4344
protected string Preview { get; set; }
4445

4546
[MethodImpl(MethodImplOptions.NoInlining)]
46-
public IElementHandle AsElement() => this as IElementHandle;
47+
public IElementHandle AsElement() => (IElementHandle)this;
4748

4849
[MethodImpl(MethodImplOptions.NoInlining)]
49-
public async Task<JsonElement?> EvaluateAsync(string expression, object arg = null)
50+
public async Task<JsonElement?> EvaluateAsync(string expression, object? arg = null)
5051
=> ScriptsHelper.ParseEvaluateResult<JsonElement?>(await SendMessageToServerAsync<JsonElement?>(
5152
"evaluateExpression",
52-
new Dictionary<string, object>
53+
new Dictionary<string, object?>
5354
{
5455
["expression"] = expression,
5556
["arg"] = ScriptsHelper.SerializedArgument(arg),
5657
}).ConfigureAwait(false));
5758

5859
[MethodImpl(MethodImplOptions.NoInlining)]
59-
public async Task<IJSHandle> EvaluateHandleAsync(string expression, object arg = null)
60+
public async Task<IJSHandle> EvaluateHandleAsync(string expression, object? arg = null)
6061
=> await SendMessageToServerAsync<JSHandle>(
6162
"evaluateExpressionHandle",
62-
new Dictionary<string, object>
63+
new Dictionary<string, object?>
6364
{
6465
["expression"] = expression,
6566
["arg"] = ScriptsHelper.SerializedArgument(arg),
6667
}).ConfigureAwait(false);
6768

6869
[MethodImpl(MethodImplOptions.NoInlining)]
69-
public async Task<T> EvaluateAsync<T>(string expression, object arg = null)
70+
public async Task<T> EvaluateAsync<T>(string expression, object? arg = null)
7071
=> ScriptsHelper.ParseEvaluateResult<T>(await SendMessageToServerAsync<JsonElement?>(
7172
"evaluateExpression",
72-
new Dictionary<string, object>
73+
new Dictionary<string, object?>
7374
{
7475
["expression"] = expression,
7576
["arg"] = ScriptsHelper.SerializedArgument(arg),
@@ -81,7 +82,7 @@ public async Task<T> EvaluateAsync<T>(string expression, object arg = null)
8182
[MethodImpl(MethodImplOptions.NoInlining)]
8283
public async Task<IJSHandle> GetPropertyAsync(string propertyName) => await SendMessageToServerAsync<JSHandle>(
8384
"getProperty",
84-
new Dictionary<string, object>
85+
new Dictionary<string, object?>
8586
{
8687
["name"] = propertyName,
8788
}).ConfigureAwait(false);
@@ -90,7 +91,7 @@ public async Task<IJSHandle> GetPropertyAsync(string propertyName) => await Send
9091
public async Task<Dictionary<string, IJSHandle>> GetPropertiesAsync()
9192
{
9293
var result = new Dictionary<string, IJSHandle>();
93-
var channelResult = (await SendMessageToServerAsync("getPropertyList").ConfigureAwait(false))?
94+
var channelResult = (await SendMessageToServerAsync("getPropertyList").ConfigureAwait(false)).Value
9495
.GetProperty("properties").ToObject<List<JSElementProperty>>(_connection.DefaultJsonSerializerOptions);
9596

9697
foreach (var kv in channelResult)
@@ -119,7 +120,7 @@ public async ValueTask DisposeAsync()
119120

120121
internal class JSElementProperty
121122
{
122-
public string Name { get; set; }
123+
public string Name { get; set; } = null!;
123124

124-
public JSHandle Value { get; set; }
125+
public JSHandle Value { get; set; } = null!;
125126
}

src/Playwright/Core/JsonPipe.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424

25+
#nullable enable
2526
using System;
2627
using System.Collections.Generic;
2728
using System.Runtime.CompilerServices;
@@ -42,9 +43,9 @@ public JsonPipe(ChannelOwner parent, string guid, JsonPipeInitializer initialize
4243
_initializer = initializer;
4344
}
4445

45-
public event EventHandler<PlaywrightServerMessage> Message;
46+
public event EventHandler<PlaywrightServerMessage>? Message;
4647

47-
public event EventHandler<string> Closed;
48+
public event EventHandler<string?>? Closed;
4849

4950
internal override void OnMessage(string method, JsonElement serverParams)
5051
{
@@ -64,7 +65,7 @@ internal override void OnMessage(string method, JsonElement serverParams)
6465
public Task CloseAsync() => SendMessageToServerAsync("close");
6566

6667
[MethodImpl(MethodImplOptions.NoInlining)]
67-
public Task SendAsync(object message) => SendMessageToServerAsync("send", new Dictionary<string, object>
68+
public Task SendAsync(object message) => SendMessageToServerAsync("send", new Dictionary<string, object?>
6869
{
6970
{ "message", message },
7071
});

src/Playwright/Core/Keyboard.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
#nullable enable
2425

2526
using System.Collections.Generic;
2627
using System.Threading.Tasks;
@@ -39,32 +40,32 @@ public Keyboard(Page page)
3940
public Task DownAsync(string key)
4041
=> _page.SendMessageToServerAsync(
4142
"keyboardDown",
42-
new Dictionary<string, object>
43+
new Dictionary<string, object?>
4344
{
4445
["key"] = key,
4546
});
4647

4748
public Task UpAsync(string key)
4849
=> _page.SendMessageToServerAsync(
4950
"keyboardUp",
50-
new Dictionary<string, object>
51+
new Dictionary<string, object?>
5152
{
5253
["key"] = key,
5354
});
5455

55-
public Task PressAsync(string key, KeyboardPressOptions options = default)
56+
public Task PressAsync(string key, KeyboardPressOptions? options = default)
5657
=> _page.SendMessageToServerAsync(
5758
"keyboardPress",
58-
new Dictionary<string, object>
59+
new Dictionary<string, object?>
5960
{
6061
["key"] = key,
6162
["delay"] = options?.Delay,
6263
});
6364

64-
public Task TypeAsync(string text, KeyboardTypeOptions options = default)
65+
public Task TypeAsync(string text, KeyboardTypeOptions? options = default)
6566
=> _page.SendMessageToServerAsync(
6667
"keyboardType",
67-
new Dictionary<string, object>
68+
new Dictionary<string, object?>
6869
{
6970
["text"] = text,
7071
["delay"] = options?.Delay,
@@ -73,7 +74,7 @@ public Task TypeAsync(string text, KeyboardTypeOptions options = default)
7374
public Task InsertTextAsync(string text)
7475
=> _page.SendMessageToServerAsync(
7576
"keyboardInsertText",
76-
new Dictionary<string, object>
77+
new Dictionary<string, object?>
7778
{
7879
["text"] = text,
7980
});

0 commit comments

Comments
 (0)