Skip to content

Commit 53310f7

Browse files
committed
Rename and clean up DoubleConverter
1 parent 0d8f906 commit 53310f7

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

dotnet/src/webdriver/BiDi/Communication/Json/Converters/DoubleConverter.cs renamed to dotnet/src/webdriver/BiDi/Communication/Json/Converters/BiDiDoubleConverter.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="DoubleConverter.cs" company="Selenium Committers">
1+
// <copyright file="BiDiDoubleConverter.cs" company="Selenium Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -23,9 +23,13 @@
2323

2424
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters
2525
{
26-
internal class DoubleConverter : JsonConverter<double>
26+
/// <summary>
27+
/// Serializes and deserializes <see cref="Double"/> into a
28+
/// <see href="https://w3c.github.io/webdriver-bidi/#type-script-PrimitiveProtocolValue">BiDi spec-compliant number value</see>.
29+
/// </summary>
30+
internal sealed class BiDiDoubleConverter : JsonConverter<double>
2731
{
28-
public override double Read(ref Utf8JsonReader reader, System.Type typeToConvert, JsonSerializerOptions options)
32+
public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
2933
{
3034
if (reader.TryGetDouble(out double d))
3135
{
@@ -34,19 +38,19 @@ public override double Read(ref Utf8JsonReader reader, System.Type typeToConvert
3438

3539
var str = reader.GetString() ?? throw new JsonException();
3640

37-
if (str.Equals("-0", System.StringComparison.Ordinal))
41+
if (str.Equals("-0", StringComparison.Ordinal))
3842
{
3943
return -0.0;
4044
}
41-
else if (str.Equals("NaN", System.StringComparison.Ordinal))
45+
else if (str.Equals("NaN", StringComparison.Ordinal))
4246
{
4347
return double.NaN;
4448
}
45-
else if (str.Equals("Infinity", System.StringComparison.Ordinal))
49+
else if (str.Equals("Infinity", StringComparison.Ordinal))
4650
{
4751
return double.PositiveInfinity;
4852
}
49-
else if (str.Equals("-Infinity", System.StringComparison.Ordinal))
53+
else if (str.Equals("-Infinity", StringComparison.Ordinal))
5054
{
5155
return double.NegativeInfinity;
5256
}

dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public abstract record PrimitiveProtocolLocalValue : LocalValue
7676

7777
}
7878

79-
public record Number([property: JsonConverter(typeof(DoubleConverter))] double Value) : PrimitiveProtocolLocalValue
79+
public record Number([property: JsonConverter(typeof(BiDiDoubleConverter))] double Value) : PrimitiveProtocolLocalValue
8080
{
8181
public static explicit operator Number(double n) => new Number(n);
8282
}

dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static implicit operator string(RemoteValue remoteValue)
9292
throw new BiDiException("Cannot convert .....");
9393
}
9494

95-
public record Number([property: JsonConverter(typeof(DoubleConverter))] double Value) : PrimitiveProtocolRemoteValue;
95+
public record Number([property: JsonConverter(typeof(BiDiDoubleConverter))] double Value) : PrimitiveProtocolRemoteValue;
9696

9797
public record Boolean(bool Value) : PrimitiveProtocolRemoteValue;
9898

0 commit comments

Comments
 (0)