Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Playwright/Transport/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ public Connection(LocalUtils localUtils = null)
JsonSerializerOptions NewJsonSerializerOptions(bool keepNulls)
{
var options = JsonExtensions.GetNewDefaultSerializerOptions(keepNulls);
options.Converters.Add(new ChannelToGuidConverter(this));
options.Converters.Add(new ChannelOwnerToGuidConverter<JSHandle>(this));
options.Converters.Add(new ChannelOwnerToGuidConverter<ElementHandle>(this));

// Workaround for https://github.com/dotnet/runtime/issues/46522
options.Converters.Add(new ChannelOwnerConverterFactory(this));
// Workaround for https://github.com/dotnet/runtime/issues/46522
options.Converters.Add(new ChannelOwnerListToGuidListConverter<WritableStream>(this));
return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,32 @@
*/

using System;
using System.Runtime.InteropServices.ComTypes;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.Playwright.Transport.Converters;

internal class ChannelOwnerToGuidConverter<T>
: JsonConverter<T>
internal class ChannelOwnerConverterFactory : JsonConverterFactory
{
private readonly Connection _connection;

public ChannelOwnerConverterFactory(Connection connection)
{
_connection = connection;
}

public override bool CanConvert(Type typeToConvert) => typeof(ChannelOwner).IsAssignableFrom(typeToConvert);

public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
return (JsonConverter)Activator.CreateInstance(
typeof(ChannelOwnerToGuidConverter<>).MakeGenericType(new Type[] { typeToConvert }),
new object[] { _connection });
}
}

internal class ChannelOwnerToGuidConverter<T> : JsonConverter<T>
where T : ChannelOwner
{
private readonly Connection _connection;
Expand All @@ -39,9 +58,6 @@ public ChannelOwnerToGuidConverter(Connection connection)
_connection = connection;
}

public override bool CanConvert(Type type)
=> (typeof(T) == typeof(ChannelOwner) && typeof(T).IsAssignableFrom(type)) || type == typeof(T);

public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
using JsonDocument document = JsonDocument.ParseValue(ref reader);
Expand Down
55 changes: 0 additions & 55 deletions src/Playwright/Transport/Converters/ChannelToGuidConverter.cs

This file was deleted.