Skip to content

Commit 7eecb0a

Browse files
committed
Extension
1 parent e7d4076 commit 7eecb0a

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs

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

20+
using OpenQA.Selenium.BiDi.Communication.Json.Internal;
2021
using OpenQA.Selenium.BiDi.Modules.Browser;
2122
using System;
2223
using System.Collections.Generic;
2324
using System.Text.Json;
2425
using System.Text.Json.Serialization;
25-
using System.Text.Json.Serialization.Metadata;
2626

2727
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;
2828

@@ -31,7 +31,7 @@ internal class GetClientWindowsResultConverter : JsonConverter<GetClientWindowsR
3131
public override GetClientWindowsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3232
{
3333
using var doc = JsonDocument.ParseValue(ref reader);
34-
var clientWindows = doc.RootElement.GetProperty("clientWindows").Deserialize((JsonTypeInfo<IReadOnlyList<ClientWindowInfo>>)options.GetTypeInfo(typeof(IReadOnlyList<ClientWindowInfo>)));
34+
var clientWindows = doc.RootElement.GetProperty("clientWindows").Deserialize(options.GetTypeInfo<IReadOnlyList<ClientWindowInfo>>());
3535

3636
return new GetClientWindowsResult(clientWindows!);
3737
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs

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

20+
using OpenQA.Selenium.BiDi.Communication.Json.Internal;
2021
using OpenQA.Selenium.BiDi.Modules.Storage;
2122
using System;
2223
using System.Collections.Generic;
@@ -31,7 +32,7 @@ internal class GetCookiesResultConverter : JsonConverter<GetCookiesResult>
3132
public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3233
{
3334
using var doc = JsonDocument.ParseValue(ref reader);
34-
var cookies = doc.RootElement.GetProperty("cookies").Deserialize((JsonTypeInfo<IReadOnlyList<Modules.Network.Cookie>>)options.GetTypeInfo(typeof(IReadOnlyList<Modules.Network.Cookie>)));
35+
var cookies = doc.RootElement.GetProperty("cookies").Deserialize(options.GetTypeInfo<IReadOnlyList<Modules.Network.Cookie>>());
3536
var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize((JsonTypeInfo<PartitionKey>)options.GetTypeInfo(typeof(PartitionKey)));
3637

3738
return new GetCookiesResult(cookies!, partitionKey!);

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs

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

20+
using OpenQA.Selenium.BiDi.Communication.Json.Internal;
2021
using OpenQA.Selenium.BiDi.Modules.Script;
2122
using System;
2223
using System.Collections.Generic;
2324
using System.Text.Json;
2425
using System.Text.Json.Serialization;
25-
using System.Text.Json.Serialization.Metadata;
2626

2727
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;
2828

@@ -31,7 +31,7 @@ internal class GetRealmsResultConverter : JsonConverter<GetRealmsResult>
3131
public override GetRealmsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3232
{
3333
using var doc = JsonDocument.ParseValue(ref reader);
34-
var realms = doc.RootElement.GetProperty("realms").Deserialize((JsonTypeInfo<IReadOnlyList<RealmInfo>>)options.GetTypeInfo(typeof(IReadOnlyList<RealmInfo>)));
34+
var realms = doc.RootElement.GetProperty("realms").Deserialize(options.GetTypeInfo<IReadOnlyList<RealmInfo>>());
3535

3636
return new GetRealmsResult(realms!);
3737
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs

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

20+
using OpenQA.Selenium.BiDi.Communication.Json.Internal;
2021
using OpenQA.Selenium.BiDi.Modules.Browser;
2122
using System;
2223
using System.Collections.Generic;
2324
using System.Text.Json;
2425
using System.Text.Json.Serialization;
25-
using System.Text.Json.Serialization.Metadata;
2626

2727
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;
2828

@@ -31,7 +31,7 @@ internal class GetUserContextsResultConverter : JsonConverter<GetUserContextsRes
3131
public override GetUserContextsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3232
{
3333
using var doc = JsonDocument.ParseValue(ref reader);
34-
var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize((JsonTypeInfo<IReadOnlyList<UserContextInfo>>)options.GetTypeInfo(typeof(IReadOnlyList<UserContextInfo>)));
34+
var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize(options.GetTypeInfo<IReadOnlyList<UserContextInfo>>());
3535

3636
return new GetUserContextsResult(userContexts!);
3737
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs

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

20+
using OpenQA.Selenium.BiDi.Communication.Json.Internal;
2021
using OpenQA.Selenium.BiDi.Modules.Input;
2122
using System;
2223
using System.Collections.Generic;
2324
using System.Diagnostics.CodeAnalysis;
2425
using System.Linq;
2526
using System.Text.Json;
2627
using System.Text.Json.Serialization;
27-
using System.Text.Json.Serialization.Metadata;
2828

2929
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;
3030

@@ -48,31 +48,31 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria
4848
case KeyActions keys:
4949
writer.WriteString("type", "key");
5050
writer.WritePropertyName("actions");
51-
JsonSerializer.Serialize(writer, keys.Actions.Select(a => a as IKeySourceAction), (JsonTypeInfo<IEnumerable<IKeySourceAction?>>)options.GetTypeInfo(typeof(IEnumerable<IKeySourceAction?>)));
51+
JsonSerializer.Serialize(writer, keys.Actions.Select(a => a as IKeySourceAction), options.GetTypeInfo<IEnumerable<IKeySourceAction?>>());
5252

5353
break;
5454
case PointerActions pointers:
5555
writer.WriteString("type", "pointer");
5656
if (pointers.Options is not null)
5757
{
5858
writer.WritePropertyName("parameters");
59-
JsonSerializer.Serialize(writer, pointers.Options, (JsonTypeInfo<PointerParameters>)options.GetTypeInfo(typeof(PointerParameters)));
59+
JsonSerializer.Serialize(writer, pointers.Options, options.GetTypeInfo(typeof(PointerParameters)));
6060
}
6161

6262
writer.WritePropertyName("actions");
63-
JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as IPointerSourceAction), (JsonTypeInfo<IEnumerable<IPointerSourceAction?>>)options.GetTypeInfo(typeof(IEnumerable<IPointerSourceAction?>)));
63+
JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as IPointerSourceAction), options.GetTypeInfo<IEnumerable<IPointerSourceAction?>>());
6464

6565
break;
6666
case WheelActions wheels:
6767
writer.WriteString("type", "wheel");
6868
writer.WritePropertyName("actions");
69-
JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as IWheelSourceAction), (JsonTypeInfo<IEnumerable<IWheelSourceAction?>>)options.GetTypeInfo(typeof(IEnumerable<IWheelSourceAction?>)));
69+
JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as IWheelSourceAction), options.GetTypeInfo<IEnumerable<IWheelSourceAction?>>());
7070

7171
break;
7272
case NoneActions none:
7373
writer.WriteString("type", "none");
7474
writer.WritePropertyName("actions");
75-
JsonSerializer.Serialize(writer, none.Actions.Select(a => a as INoneSourceAction), (JsonTypeInfo<IEnumerable<INoneSourceAction?>>)options.GetTypeInfo(typeof(IEnumerable<INoneSourceAction?>)));
75+
JsonSerializer.Serialize(writer, none.Actions.Select(a => a as INoneSourceAction), options.GetTypeInfo<IEnumerable<INoneSourceAction?>>());
7676

7777
break;
7878
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs

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

20+
using OpenQA.Selenium.BiDi.Communication.Json.Internal;
2021
using OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2122
using OpenQA.Selenium.BiDi.Modules.Script;
2223
using System;
2324
using System.Collections.Generic;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
26-
using System.Text.Json.Serialization.Metadata;
2727

2828
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;
2929

@@ -32,7 +32,7 @@ internal class LocateNodesResultConverter : JsonConverter<LocateNodesResult>
3232
public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3333
{
3434
using var doc = JsonDocument.ParseValue(ref reader);
35-
var nodes = doc.RootElement.GetProperty("nodes").Deserialize((JsonTypeInfo<IReadOnlyList<NodeRemoteValue>>)options.GetTypeInfo(typeof(IReadOnlyList<NodeRemoteValue>)));
35+
var nodes = doc.RootElement.GetProperty("nodes").Deserialize(options.GetTypeInfo<IReadOnlyList<NodeRemoteValue>>());
3636

3737
return new LocateNodesResult(nodes!);
3838
}

dotnet/src/webdriver/BiDi/Communication/Json/Internal/JsonExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// </copyright>
1919

2020
using System.Text.Json;
21+
using System.Text.Json.Serialization.Metadata;
2122

2223
namespace OpenQA.Selenium.BiDi.Communication.Json.Internal;
2324

@@ -51,4 +52,9 @@ public static string GetDiscriminator(this ref Utf8JsonReader reader, string nam
5152

5253
return discriminator ?? throw new JsonException($"Couldn't determine '{name}' discriminator.");
5354
}
55+
56+
public static JsonTypeInfo<T> GetTypeInfo<T>(this JsonSerializerOptions options)
57+
{
58+
return (JsonTypeInfo<T>)options.GetTypeInfo(typeof(T));
59+
}
5460
}

0 commit comments

Comments
 (0)