Skip to content

Commit ad4ad58

Browse files
committed
Fix typeconverter culture handling
I guess tests are actually useful?
1 parent 77cda91 commit ad4ad58

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/BizHawk.Emulation.Common/Json/TypeConverterJsonAdapter.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.ComponentModel;
1+
using System.ComponentModel;
2+
using System.Globalization;
23
using System.Linq;
34
using System.Reflection;
45
using System.Text.Json;
@@ -17,14 +18,14 @@ public class TypeConverterJsonAdapter<T> : JsonConverter<T>
1718
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
1819
{
1920
var converter = TypeDescriptor.GetConverter(typeToConvert);
20-
return (T)converter.ConvertFromString(reader.GetString())!;
21+
return (T)converter.ConvertFromString(null!, CultureInfo.InvariantCulture, reader.GetString())!;
2122
}
2223

2324
/// <inheritdoc/>
2425
public override void Write(Utf8JsonWriter writer, T objectToWrite, JsonSerializerOptions options)
2526
{
2627
var converter = TypeDescriptor.GetConverter(objectToWrite!);
27-
writer.WriteStringValue(converter.ConvertToString(objectToWrite!));
28+
writer.WriteStringValue(converter.ConvertToString(null!, CultureInfo.InvariantCulture, objectToWrite!));
2829
}
2930

3031
/// <inheritdoc/>

src/BizHawk.Tests/Client.Common/config/SerializationStabilityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void TestSerializationTypeConverter()
126126
{
127127
var color = Color.FromArgb(200, 255, 13, 42);
128128
string serialized = JsonSerializer.Serialize(color, ConfigService.SerializerOptions);
129-
Assert.AreEqual("\"200; 255; 13; 42\"", serialized);
129+
Assert.AreEqual("\"200, 255, 13, 42\"", serialized);
130130

131131
var newColor = JsonSerializer.Deserialize<Color>(serialized, ConfigService.SerializerOptions);
132132
Assert.AreEqual(color, newColor);

0 commit comments

Comments
 (0)