Skip to content

Commit b9ea380

Browse files
committed
One to one string conversion
1 parent 373fd9a commit b9ea380

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

dotnet/src/webdriver/BiDi/Network/BytesValue.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ public abstract record BytesValue
3030
public static implicit operator BytesValue(string value) => new StringBytesValue(value);
3131
public static implicit operator BytesValue(byte[] value) => new Base64BytesValue(Convert.ToBase64String(value));
3232

33-
public static explicit operator string(BytesValue value) => value switch
33+
public static explicit operator string(BytesValue value)
3434
{
35-
StringBytesValue stringBytesValue => stringBytesValue.Value,
36-
Base64BytesValue base64BytesValue => System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(base64BytesValue.Value)),
37-
_ => throw new InvalidCastException($"Cannot cast '{value.GetType()}' to '{typeof(string)}'.")
38-
};
35+
if (value is StringBytesValue stringBytesValue)
36+
{
37+
return stringBytesValue.Value;
38+
}
39+
40+
throw new InvalidCastException($"Cannot cast '{value.GetType()}' to '{typeof(string)}'.");
41+
}
3942
}
4043

4144
public sealed record StringBytesValue(string Value) : BytesValue;

0 commit comments

Comments
 (0)