Skip to content

Commit d0f2745

Browse files
authored
chore: enable #nullable iteration 3 (#3172)
1 parent 5d50f87 commit d0f2745

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+353
-333
lines changed

src/Playwright/API/PlaywrightException.cs

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

25+
#nullable enable
2526
using System;
2627

2728
namespace Microsoft.Playwright;

src/Playwright/API/Supplements/IAPIRequestContext.cs

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

25+
#nullable enable
2526
using System;
2627

2728
namespace Microsoft.Playwright;

src/Playwright/API/Supplements/IBrowser.cs

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

25+
#nullable enable
2526
using System;
2627

2728
namespace Microsoft.Playwright;

src/Playwright/API/Supplements/ICDPSession.cs

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

25+
#nullable enable
2526
using System;
2627

2728
namespace Microsoft.Playwright

src/Playwright/API/Supplements/IElementHandle.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
* SOFTWARE.
2323
*/
2424

25+
#nullable enable
2526
using System.Text.Json;
2627
using System.Threading.Tasks;
2728

2829
namespace Microsoft.Playwright;
2930

3031
public partial interface IElementHandle
3132
{
32-
Task<JsonElement?> EvalOnSelectorAsync(string selector, string expression, object arg = null);
33+
Task<JsonElement?> EvalOnSelectorAsync(string selector, string expression, object? arg = null);
3334
}

src/Playwright/API/Supplements/IFrame.cs

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

25+
#nullable enable
2526
using System.Text.Json;
2627
using System.Threading.Tasks;
2728

2829
namespace Microsoft.Playwright;
2930

3031
public partial interface IFrame
3132
{
32-
Task<JsonElement?> EvaluateAsync(string expression, object arg = default);
33+
Task<JsonElement?> EvaluateAsync(string expression, object? arg = default);
3334

34-
Task<JsonElement?> EvalOnSelectorAsync(string selector, string expression, object arg = default);
35+
Task<JsonElement?> EvalOnSelectorAsync(string selector, string expression, object? arg = default);
3536

36-
Task<JsonElement?> EvalOnSelectorAllAsync(string selector, string expression, object arg = default);
37+
Task<JsonElement?> EvalOnSelectorAllAsync(string selector, string expression, object? arg = default);
3738
}

src/Playwright/API/Supplements/IJSHandle.cs

Lines changed: 2 additions & 1 deletion
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.Text.Json;
2728
using System.Threading.Tasks;
@@ -31,5 +32,5 @@ namespace Microsoft.Playwright;
3132
public partial interface IJSHandle : IAsyncDisposable
3233
{
3334
/// <inheritdoc cref="EvaluateAsync{T}(string, object)" />
34-
Task<JsonElement?> EvaluateAsync(string expression, object arg = null);
35+
Task<JsonElement?> EvaluateAsync(string expression, object? arg = null);
3536
}

src/Playwright/API/Supplements/ILocator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
* SOFTWARE.
2323
*/
2424

25+
#nullable enable
2526
using System.Text.Json;
2627
using System.Threading.Tasks;
2728

2829
namespace Microsoft.Playwright;
2930

3031
public partial interface ILocator
3132
{
32-
Task<JsonElement?> EvaluateAsync(string expression, object arg = null, LocatorEvaluateOptions options = null);
33+
Task<JsonElement?> EvaluateAsync(string expression, object? arg = null, LocatorEvaluateOptions? options = null);
3334
}

src/Playwright/API/Supplements/IPlaywright.cs

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

25+
#nullable enable
2526
using System;
2627

2728
namespace Microsoft.Playwright;

src/Playwright/API/Supplements/IResponse.cs

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

25+
#nullable enable
2526
using System.Threading.Tasks;
2627

2728
namespace Microsoft.Playwright;

src/Playwright/API/TargetClosedException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
24+
#nullable enable
2525
using System;
2626
using Microsoft.Playwright.Core;
2727

@@ -33,7 +33,7 @@ internal TargetClosedException() : base(DriverMessages.TargetClosedExceptionMess
3333
{
3434
}
3535

36-
internal TargetClosedException(string message) : base(message ?? DriverMessages.TargetClosedExceptionMessage)
36+
internal TargetClosedException(string? message) : base(message ?? DriverMessages.TargetClosedExceptionMessage)
3737
{
3838
}
3939

src/Playwright/API/Types/BindingSource.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@
2222
* SOFTWARE.
2323
*/
2424

25+
#nullable enable
2526
namespace Microsoft.Playwright;
2627

2728
public class BindingSource
2829
{
30+
internal BindingSource(IBrowserContext context, IPage page, IFrame frame)
31+
{
32+
Context = context;
33+
Page = page;
34+
Frame = frame;
35+
}
36+
2937
public IBrowserContext Context { get; set; }
3038

3139
public IPage Page { get; set; }

src/Playwright/API/Types/DialogType.cs

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

25+
#nullable enable
2526
namespace Microsoft.Playwright;
2627

2728
/// <summary>

src/Playwright/API/Types/PaperFormat.cs

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

25+
#nullable enable
2526
namespace Microsoft.Playwright;
2627

2728
public static class PaperFormat

src/Playwright/API/Types/RequestAbortErrorCode.cs

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

25+
#nullable enable
2526
namespace Microsoft.Playwright;
2627

2728
/// <summary>

src/Playwright/API/Types/ViewportSize.cs

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

25+
#nullable enable
2526
namespace Microsoft.Playwright;
2627

2728
/// <summary>

src/Playwright/Assertions.cs

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

25+
#nullable enable
2526
using Microsoft.Playwright.Core;
2627

2728
namespace Microsoft.Playwright;

src/Playwright/BrowserType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
24+
#nullable enable
2525
namespace Microsoft.Playwright;
2626

2727
/// <summary>

src/Playwright/Core/APIRequest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
24+
#nullable enable
2525
using System.Collections.Generic;
2626
using System.IO;
2727
using System.Text.Json;
@@ -39,9 +39,9 @@ public APIRequest(PlaywrightImpl playwright)
3939
_playwright = playwright;
4040
}
4141

42-
async Task<IAPIRequestContext> IAPIRequest.NewContextAsync(APIRequestNewContextOptions options)
42+
async Task<IAPIRequestContext> IAPIRequest.NewContextAsync(APIRequestNewContextOptions? options)
4343
{
44-
var args = new Dictionary<string, object>()
44+
var args = new Dictionary<string, object?>()
4545
{
4646
["baseURL"] = options?.BaseURL,
4747
["userAgent"] = options?.UserAgent,
@@ -54,7 +54,7 @@ async Task<IAPIRequestContext> IAPIRequest.NewContextAsync(APIRequestNewContextO
5454
["clientCertificates"] = Browser.ToClientCertificatesProtocol(options?.ClientCertificates),
5555
["failOnStatusCode"] = options?.FailOnStatusCode,
5656
};
57-
string storageState = options?.StorageState;
57+
var storageState = options?.StorageState;
5858
if (!string.IsNullOrEmpty(options?.StorageStatePath))
5959
{
6060
if (!File.Exists(options?.StorageStatePath))
@@ -64,7 +64,7 @@ async Task<IAPIRequestContext> IAPIRequest.NewContextAsync(APIRequestNewContextO
6464

6565
storageState = File.ReadAllText(options?.StorageStatePath);
6666
}
67-
if (!string.IsNullOrEmpty(storageState))
67+
if (!string.IsNullOrEmpty(storageState) && storageState != null)
6868
{
6969
args.Add("storageState", JsonSerializer.Deserialize<object>(storageState, Helpers.JsonExtensions.DefaultJsonSerializerOptions));
7070
}

src/Playwright/Core/APIRequestContext.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
24+
#nullable enable
2525
using System;
2626
using System.Collections.Generic;
2727
using System.IO;
@@ -38,9 +38,9 @@ namespace Microsoft.Playwright.Core;
3838
internal class APIRequestContext : ChannelOwner, IAPIRequestContext
3939
{
4040
internal readonly Tracing _tracing;
41-
private string _closeReason;
41+
private string? _closeReason;
4242

43-
internal APIRequest _request;
43+
internal APIRequest? _request;
4444

4545
public APIRequestContext(ChannelOwner parent, string guid, APIRequestContextInitializer initializer) : base(parent, guid)
4646
{
@@ -53,12 +53,12 @@ public async ValueTask DisposeAsync()
5353
await DisposeAsync(null).ConfigureAwait(false);
5454
}
5555

56-
internal async ValueTask DisposeAsync(string reason)
56+
internal async ValueTask DisposeAsync(string? reason)
5757
{
5858
_closeReason = reason;
5959
try
6060
{
61-
await SendMessageToServerAsync("dispose", new Dictionary<string, object>
61+
await SendMessageToServerAsync("dispose", new Dictionary<string, object?>
6262
{
6363
["reason"] = reason,
6464
}).ConfigureAwait(false);
@@ -71,10 +71,10 @@ internal async ValueTask DisposeAsync(string reason)
7171
}
7272

7373
[MethodImpl(MethodImplOptions.NoInlining)]
74-
public Task<IAPIResponse> FetchAsync(IRequest request, APIRequestContextOptions options = null)
74+
public Task<IAPIResponse> FetchAsync(IRequest request, APIRequestContextOptions? options = null)
7575
=> InnerFetchAsync(request, null, options);
7676

77-
internal async Task<IAPIResponse> InnerFetchAsync(IRequest request, string urlOverride, APIRequestContextOptions options = null)
77+
internal async Task<IAPIResponse> InnerFetchAsync(IRequest request, string? urlOverride, APIRequestContextOptions? options = null)
7878
{
7979
options ??= new APIRequestContextOptions();
8080
if (string.IsNullOrEmpty(options.Method))
@@ -94,9 +94,9 @@ internal async Task<IAPIResponse> InnerFetchAsync(IRequest request, string urlOv
9494
}
9595

9696
[MethodImpl(MethodImplOptions.NoInlining)]
97-
public async Task<IAPIResponse> FetchAsync(string url, APIRequestContextOptions options = null)
97+
public async Task<IAPIResponse> FetchAsync(string url, APIRequestContextOptions? options = null)
9898
{
99-
if (!string.IsNullOrEmpty(_closeReason))
99+
if (!string.IsNullOrEmpty(_closeReason) && _closeReason != null)
100100
{
101101
throw new PlaywrightException(_closeReason);
102102
}
@@ -114,9 +114,9 @@ public async Task<IAPIResponse> FetchAsync(string url, APIRequestContextOptions
114114
{
115115
throw new PlaywrightException("Only one of 'data', 'form' or 'multipart' can be specified");
116116
}
117-
byte[] postData = null;
118-
object jsonData = null;
119-
string dataString = !string.IsNullOrEmpty(options.Data) ? options.Data : options.DataString;
117+
byte[]? postData = null;
118+
object? jsonData = null;
119+
string dataString = (!string.IsNullOrEmpty(options.Data) && options.Data != null) ? options.Data : options.DataString!;
120120
if (!string.IsNullOrEmpty(dataString))
121121
{
122122
if (IsJsonContentType(options.Headers?.ToDictionary(x => x.Key, x => x.Value)))
@@ -137,29 +137,29 @@ public async Task<IAPIResponse> FetchAsync(string url, APIRequestContextOptions
137137
jsonData = JsonSerializer.Serialize(options.DataObject, _connection.DefaultJsonSerializerOptionsKeepNulls);
138138
}
139139

140-
var message = new Dictionary<string, object>
140+
var message = new Dictionary<string, object?>
141141
{
142142
["url"] = url,
143143
["method"] = options?.Method,
144144
["failOnStatusCode"] = options?.FailOnStatusCode,
145145
["ignoreHTTPSErrors"] = options?.IgnoreHTTPSErrors,
146146
["maxRedirects"] = options?.MaxRedirects,
147147
["maxRetries"] = options?.MaxRetries,
148-
["timeout"] = options.Timeout,
149-
["params"] = options.Params?.ToDictionary(x => x.Key, x => x.Value.ToString()).ToProtocol(),
150-
["encodedParams"] = options.ParamsString,
151-
["headers"] = options.Headers?.ToProtocol(),
148+
["timeout"] = options?.Timeout,
149+
["params"] = options?.Params?.ToDictionary(x => x.Key, x => x.Value.ToString()).ToProtocol(),
150+
["encodedParams"] = options?.ParamsString,
151+
["headers"] = options?.Headers?.ToProtocol(),
152152
["jsonData"] = jsonData,
153153
["postData"] = postData != null ? Convert.ToBase64String(postData) : null,
154-
["formData"] = ((FormData)options.Form)?.ToProtocol(throwWhenSerializingFilePayloads: true),
155-
["multipartData"] = ((FormData)options.Multipart)?.ToProtocol(),
154+
["formData"] = (options?.Form as FormData)?.ToProtocol(throwWhenSerializingFilePayloads: true),
155+
["multipartData"] = (options?.Multipart as FormData)?.ToProtocol(),
156156
};
157157

158158
var response = await SendMessageToServerAsync("fetch", message).ConfigureAwait(false);
159-
return new APIResponse(this, response?.GetProperty("response").ToObject<Transport.Protocol.APIResponse>());
159+
return new APIResponse(this, response?.GetProperty("response").ToObject<Transport.Protocol.APIResponse>()!);
160160
}
161161

162-
private bool IsJsonContentType(IDictionary<string, string> headers)
162+
private bool IsJsonContentType(IDictionary<string, string>? headers)
163163
{
164164
if (headers == null)
165165
{
@@ -187,32 +187,32 @@ private bool IsJsonParsable(string dataString)
187187
}
188188

189189
[MethodImpl(MethodImplOptions.NoInlining)]
190-
public Task<IAPIResponse> DeleteAsync(string url, APIRequestContextOptions options = null) => FetchAsync(url, WithMethod(options, "DELETE"));
190+
public Task<IAPIResponse> DeleteAsync(string url, APIRequestContextOptions? options = null) => FetchAsync(url, WithMethod(options, "DELETE"));
191191

192192
[MethodImpl(MethodImplOptions.NoInlining)]
193-
public Task<IAPIResponse> GetAsync(string url, APIRequestContextOptions options = null) => FetchAsync(url, WithMethod(options, "GET"));
193+
public Task<IAPIResponse> GetAsync(string url, APIRequestContextOptions? options = null) => FetchAsync(url, WithMethod(options, "GET"));
194194

195195
[MethodImpl(MethodImplOptions.NoInlining)]
196-
public Task<IAPIResponse> HeadAsync(string url, APIRequestContextOptions options = null) => FetchAsync(url, WithMethod(options, "HEAD"));
196+
public Task<IAPIResponse> HeadAsync(string url, APIRequestContextOptions? options = null) => FetchAsync(url, WithMethod(options, "HEAD"));
197197

198198
[MethodImpl(MethodImplOptions.NoInlining)]
199-
public Task<IAPIResponse> PatchAsync(string url, APIRequestContextOptions options = null) => FetchAsync(url, WithMethod(options, "PATCH"));
199+
public Task<IAPIResponse> PatchAsync(string url, APIRequestContextOptions? options = null) => FetchAsync(url, WithMethod(options, "PATCH"));
200200

201201
[MethodImpl(MethodImplOptions.NoInlining)]
202-
public Task<IAPIResponse> PostAsync(string url, APIRequestContextOptions options = null) => FetchAsync(url, WithMethod(options, "POST"));
202+
public Task<IAPIResponse> PostAsync(string url, APIRequestContextOptions? options = null) => FetchAsync(url, WithMethod(options, "POST"));
203203

204204
[MethodImpl(MethodImplOptions.NoInlining)]
205-
public Task<IAPIResponse> PutAsync(string url, APIRequestContextOptions options = null) => FetchAsync(url, WithMethod(options, "PUT"));
205+
public Task<IAPIResponse> PutAsync(string url, APIRequestContextOptions? options = null) => FetchAsync(url, WithMethod(options, "PUT"));
206206

207-
private APIRequestContextOptions WithMethod(APIRequestContextOptions options, string method)
207+
private APIRequestContextOptions WithMethod(APIRequestContextOptions? options, string method)
208208
{
209209
options = ClassUtils.Clone<APIRequestContextOptions>(options);
210210
options.Method = method;
211211
return options;
212212
}
213213

214214
[MethodImpl(MethodImplOptions.NoInlining)]
215-
public async Task<string> StorageStateAsync(APIRequestContextStorageStateOptions options = null)
215+
public async Task<string> StorageStateAsync(APIRequestContextStorageStateOptions? options = null)
216216
{
217217
string state = JsonSerializer.Serialize(
218218
await SendMessageToServerAsync<object>("storageState").ConfigureAwait(false),

0 commit comments

Comments
 (0)