Skip to content

Commit a818548

Browse files
authored
Merge pull request #24 from hlaueriksson/net8.0
TargetFramework
2 parents f644d10 + 28742c1 commit a818548

15 files changed

+54
-52
lines changed

src/PuppeteerSharp.Contrib.Extensions/InternalExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ internal static async Task<T> EvaluateFunctionWithGuardAsync<T>(this IElementHan
1212

1313
internal static IPage GuardFromNull(this IPage page)
1414
{
15-
if (page == null) throw new ArgumentNullException(nameof(page));
15+
ArgumentNullException.ThrowIfNull(page);
1616

1717
return page;
1818
}
1919

2020
internal static IResponse GuardFromNull(this IResponse response)
2121
{
22-
if (response == null) throw new ArgumentNullException(nameof(response));
22+
ArgumentNullException.ThrowIfNull(response);
2323

2424
return response;
2525
}
2626

2727
internal static IElementHandle GuardFromNull(this IElementHandle elementHandle)
2828
{
29-
if (elementHandle == null) throw new ArgumentNullException(nameof(elementHandle));
29+
ArgumentNullException.ThrowIfNull(elementHandle);
3030

3131
return elementHandle;
3232
}

src/PuppeteerSharp.Contrib.Extensions/PuppeteerSharp.Contrib.Extensions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Version>6.0.0</Version>
66
<PackageReleaseNotes>
77
⬆️ Bump PuppeteerSharp to 12.0.0

src/PuppeteerSharp.Contrib.PageObjects/DynamicProxy/InvocationExtensions.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public static bool IsGetterPropertyWithAttribute<T>(this IInvocation invocation)
2020

2121
var property = invocation.TargetType.GetProperty(invocation.Method);
2222

23-
return property.HasAttribute<T>();
23+
return property?.HasAttribute<T>() ?? false;
2424
}
2525

26-
public static T GetAttribute<T>(this IInvocation invocation)
26+
public static T? GetAttribute<T>(this IInvocation invocation)
2727
where T : Attribute
2828
{
2929
var property = invocation.TargetType.GetProperty(invocation.Method);
3030

31-
return property.GetAttribute<T>();
31+
return property?.GetAttribute<T>();
3232
}
3333

3434
public static bool IsReturning<T>(this IInvocation invocation)
@@ -50,12 +50,14 @@ public static bool IsReturningElementObjectArray(this IInvocation invocation)
5050
typeof(ElementObject[]).IsAssignableFrom(invocation.Method.ReturnType.GetGenericArguments()[0]);
5151
}
5252

53-
public static async Task<object?> GetReturnValueAsync(this IInvocation invocation, PageObject pageObject, SelectorAttribute attribute)
53+
public static async Task<object?> GetReturnValueAsync(this IInvocation invocation, PageObject pageObject, SelectorAttribute? attribute)
5454
{
5555
var page = pageObject.Page;
5656

5757
if (page == null) return null;
5858

59+
if (attribute == null) return null;
60+
5961
if (invocation.IsReturning<IElementHandle>())
6062
{
6163
return await page.QuerySelectorAsync(attribute.Selector).ConfigureAwait(false);
@@ -86,12 +88,14 @@ public static bool IsReturningElementObjectArray(this IInvocation invocation)
8688
return null;
8789
}
8890

89-
public static async Task<object?> GetReturnValueAsync(this IInvocation invocation, ElementObject elementObject, SelectorAttribute attribute)
91+
public static async Task<object?> GetReturnValueAsync(this IInvocation invocation, ElementObject elementObject, SelectorAttribute? attribute)
9092
{
9193
var element = elementObject.Element;
9294

9395
if (element == null) return null;
9496

97+
if (attribute == null) return null;
98+
9599
if (invocation.IsReturning<IElementHandle>())
96100
{
97101
return await element.QuerySelectorAsync(attribute.Selector).ConfigureAwait(false);
@@ -123,13 +127,15 @@ public static bool IsReturningElementObjectArray(this IInvocation invocation)
123127
}
124128

125129
#pragma warning disable CS0618 // Type or member is obsolete
126-
public static async Task<object?> GetReturnValueAsync(this IInvocation invocation, PageObject pageObject, XPathAttribute attribute)
130+
public static async Task<object?> GetReturnValueAsync(this IInvocation invocation, PageObject pageObject, XPathAttribute? attribute)
127131
#pragma warning restore CS0618 // Type or member is obsolete
128132
{
129133
var page = pageObject.Page;
130134

131135
if (page == null) return null;
132136

137+
if (attribute == null) return null;
138+
133139
if (invocation.IsReturning<IElementHandle[]>())
134140
{
135141
#pragma warning disable CS0618 // Type or member is obsolete
@@ -152,13 +158,15 @@ public static bool IsReturningElementObjectArray(this IInvocation invocation)
152158
}
153159

154160
#pragma warning disable CS0618 // Type or member is obsolete
155-
public static async Task<object?> GetReturnValueAsync(this IInvocation invocation, ElementObject elementObject, XPathAttribute attribute)
161+
public static async Task<object?> GetReturnValueAsync(this IInvocation invocation, ElementObject elementObject, XPathAttribute? attribute)
156162
#pragma warning restore CS0618 // Type or member is obsolete
157163
{
158164
var element = elementObject.Element;
159165

160166
if (element == null) return null;
161167

168+
if (attribute == null) return null;
169+
162170
if (invocation.IsReturning<IElementHandle[]>())
163171
{
164172
#pragma warning disable CS0618 // Type or member is obsolete

src/PuppeteerSharp.Contrib.PageObjects/DynamicProxy/ProxyFactory.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public static T PageObject<T>(IPage page, IResponse? response)
1919
return proxy;
2020
}
2121

22-
public static T? ElementObject<T>(IPage page, IElementHandle elementHandle)
22+
public static T? ElementObject<T>(IPage? page, IElementHandle elementHandle)
2323
where T : ElementObject
2424
{
25+
if (page == null) return default;
2526
if (elementHandle == null) return default;
2627

2728
var proxy = ProxyGenerator.CreateClassProxy<T>(Options, new SelectorInterceptor(), new XPathInterceptor());
@@ -40,8 +41,10 @@ public static T PageObject<T>(IPage page, IResponse? response)
4041
return proxy;
4142
}
4243

43-
public static Array ElementObjectArray(Type proxyType, IPage page, IElementHandle[] elementHandles)
44+
public static Array? ElementObjectArray(Type? proxyType, IPage page, IElementHandle[] elementHandles)
4445
{
46+
if (proxyType == null) return default;
47+
4548
var array = Array.CreateInstance(proxyType, elementHandles.Length);
4649
for (var i = 0; i < elementHandles.Length; i++)
4750
{

src/PuppeteerSharp.Contrib.PageObjects/DynamicProxy/ProxyGenerationHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
2424
methodInfo.IsReturningAsyncResult();
2525
}
2626

27-
public override bool Equals(object obj)
27+
public override bool Equals(object? obj)
2828
{
2929
return obj != null && obj.GetType() == typeof(ProxyGenerationHook);
3030
}

src/PuppeteerSharp.Contrib.PageObjects/DynamicProxy/ReflectionExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public static bool IsGetterPropertyWithAttribute<T>(this MethodInfo methodInfo)
1313
{
1414
if (!methodInfo.IsGetter()) return false;
1515

16-
var property = methodInfo.DeclaringType.GetProperty(methodInfo);
16+
var property = methodInfo.DeclaringType?.GetProperty(methodInfo);
1717

18-
return property.HasAttribute<T>();
18+
return property?.HasAttribute<T>() ?? false;
1919
}
2020

2121
public static bool IsGetter(this MethodInfo methodInfo)
@@ -29,7 +29,7 @@ public static bool HasAttribute<T>(this PropertyInfo propertyInfo)
2929
return propertyInfo.GetCustomAttributes<T>().Any();
3030
}
3131

32-
public static T GetAttribute<T>(this PropertyInfo propertyInfo)
32+
public static T? GetAttribute<T>(this PropertyInfo propertyInfo)
3333
where T : Attribute
3434
{
3535
return propertyInfo.GetCustomAttribute<T>();
@@ -40,7 +40,7 @@ public static bool IsCompilerGenerated(this MemberInfo memberInfo)
4040
return memberInfo.GetCustomAttributes<CompilerGeneratedAttribute>().Any();
4141
}
4242

43-
public static PropertyInfo GetProperty(this Type rootType, MethodInfo methodInfo)
43+
public static PropertyInfo? GetProperty(this Type rootType, MethodInfo methodInfo)
4444
{
4545
return rootType.GetProperty(methodInfo.Name.Substring(4), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
4646
}

src/PuppeteerSharp.Contrib.PageObjects/DynamicProxy/SelectorInterceptor.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public void Intercept(IInvocation invocation)
1717

1818
var tcsType = typeof(TaskCompletionSource<>).MakeGenericType(invocation.Method.ReturnType.GetGenericArguments()[0]);
1919
var tcs = Activator.CreateInstance(tcsType);
20-
invocation.ReturnValue = tcsType.GetProperty("Task").GetValue(tcs, null);
20+
invocation.ReturnValue = tcsType?.GetProperty("Task")?.GetValue(tcs, null);
2121

2222
#pragma warning disable VSTHRD105 // Avoid method overloads that assume TaskScheduler.Current
2323
#pragma warning disable VSTHRD110 // Observe result of async calls
24-
InterceptAsync(invocation).ContinueWith(_ => tcsType.GetMethod("SetResult").Invoke(tcs, [invocation.ReturnValue]));
24+
InterceptAsync(invocation).ContinueWith(_ => tcsType?.GetMethod("SetResult")?.Invoke(tcs, [invocation.ReturnValue]), TaskScheduler.Default);
2525
#pragma warning restore VSTHRD110 // Observe result of async calls
2626
#pragma warning restore VSTHRD105 // Avoid method overloads that assume TaskScheduler.Current
2727
}
@@ -34,17 +34,13 @@ private static async Task InterceptAsync(IInvocation invocation)
3434

3535
if (invocation.InvocationTarget is PageObject pageObject)
3636
{
37-
var result = await invocation.GetReturnValueAsync(pageObject, attribute).ConfigureAwait(false);
38-
39-
invocation.ReturnValue = result;
37+
invocation.ReturnValue = await invocation.GetReturnValueAsync(pageObject, attribute).ConfigureAwait(false);
4038
return;
4139
}
4240

4341
if (invocation.InvocationTarget is ElementObject elementObject)
4442
{
45-
var result = await invocation.GetReturnValueAsync(elementObject, attribute).ConfigureAwait(false);
46-
47-
invocation.ReturnValue = result;
43+
invocation.ReturnValue = await invocation.GetReturnValueAsync(elementObject, attribute).ConfigureAwait(false);
4844
return;
4945
}
5046
}

src/PuppeteerSharp.Contrib.PageObjects/DynamicProxy/XPathInterceptor.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public void Intercept(IInvocation invocation)
1717

1818
var tcsType = typeof(TaskCompletionSource<>).MakeGenericType(invocation.Method.ReturnType.GetGenericArguments()[0]);
1919
var tcs = Activator.CreateInstance(tcsType);
20-
invocation.ReturnValue = tcsType.GetProperty("Task").GetValue(tcs, null);
20+
invocation.ReturnValue = tcsType?.GetProperty("Task")?.GetValue(tcs, null);
2121

2222
#pragma warning disable VSTHRD105 // Avoid method overloads that assume TaskScheduler.Current
2323
#pragma warning disable VSTHRD110 // Observe result of async calls
24-
InterceptAsync(invocation).ContinueWith(_ => tcsType.GetMethod("SetResult").Invoke(tcs, [invocation.ReturnValue]));
24+
InterceptAsync(invocation).ContinueWith(_ => tcsType?.GetMethod("SetResult")?.Invoke(tcs, [invocation.ReturnValue]), TaskScheduler.Default);
2525
#pragma warning restore VSTHRD110 // Observe result of async calls
2626
#pragma warning restore VSTHRD105 // Avoid method overloads that assume TaskScheduler.Current
2727
}
@@ -36,17 +36,13 @@ private static async Task InterceptAsync(IInvocation invocation)
3636

3737
if (invocation.InvocationTarget is PageObject pageObject)
3838
{
39-
var result = await invocation.GetReturnValueAsync(pageObject, attribute).ConfigureAwait(false);
40-
41-
invocation.ReturnValue = result;
39+
invocation.ReturnValue = await invocation.GetReturnValueAsync(pageObject, attribute).ConfigureAwait(false);
4240
return;
4341
}
4442

4543
if (invocation.InvocationTarget is ElementObject elementObject)
4644
{
47-
var result = await invocation.GetReturnValueAsync(elementObject, attribute).ConfigureAwait(false);
48-
49-
invocation.ReturnValue = result;
45+
invocation.ReturnValue = await invocation.GetReturnValueAsync(elementObject, attribute).ConfigureAwait(false);
5046
return;
5147
}
5248
}

src/PuppeteerSharp.Contrib.PageObjects/Extensions/ElementHandleExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ public static async Task<T[]> XPathAsync<T>(this IElementHandle elementHandle, s
9494
return ProxyFactory.ElementObject<T>(elementHandle.GetPage(), result);
9595
}
9696

97-
private static IPage GetPage(this IElementHandle elementHandle)
97+
private static IPage? GetPage(this IElementHandle elementHandle)
9898
{
9999
var propertyInfo = elementHandle.GetType().GetProperty("Page", BindingFlags.NonPublic | BindingFlags.Instance);
100-
var methodInfo = propertyInfo.GetGetMethod(nonPublic: true);
100+
var methodInfo = propertyInfo?.GetGetMethod(nonPublic: true);
101101

102-
return (IPage)methodInfo.Invoke(elementHandle, null);
102+
return methodInfo?.Invoke(elementHandle, null) as IPage;
103103
}
104104

105105
private static IElementHandle GuardFromNull(this IElementHandle elementHandle)
106106
{
107-
if (elementHandle == null) throw new ArgumentNullException(nameof(elementHandle));
107+
ArgumentNullException.ThrowIfNull(elementHandle);
108108

109109
return elementHandle;
110110
}

src/PuppeteerSharp.Contrib.PageObjects/Extensions/PageExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public static async Task<T[]> XPathAsync<T>(this IPage page, string expression)
322322

323323
private static IPage GuardFromNull(this IPage page)
324324
{
325-
if (page == null) throw new ArgumentNullException(nameof(page));
325+
ArgumentNullException.ThrowIfNull(page);
326326

327327
return page;
328328
}

0 commit comments

Comments
 (0)