Skip to content

Commit

Permalink
Fix typeconverter culture handling
Browse files Browse the repository at this point in the history
I guess tests are actually useful?
  • Loading branch information
Morilli committed Sep 2, 2024
1 parent 790db80 commit 52d9cf2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/BizHawk.Emulation.Common/Json/TypeConverterJsonAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text.Json;
Expand All @@ -17,14 +18,14 @@ public class TypeConverterJsonAdapter<T> : JsonConverter<T>
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var converter = TypeDescriptor.GetConverter(typeToConvert);
return (T)converter.ConvertFromString(reader.GetString())!;
return (T)converter.ConvertFromString(null!, CultureInfo.InvariantCulture, reader.GetString())!;
}

/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, T objectToWrite, JsonSerializerOptions options)
{
var converter = TypeDescriptor.GetConverter(objectToWrite!);
writer.WriteStringValue(converter.ConvertToString(objectToWrite!));
writer.WriteStringValue(converter.ConvertToString(null!, CultureInfo.InvariantCulture, objectToWrite!));
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void TestSerializationTypeConverter()
{
var color = Color.FromArgb(200, 255, 13, 42);
string serialized = JsonSerializer.Serialize(color, ConfigService.SerializerOptions);
Assert.AreEqual("\"200; 255; 13; 42\"", serialized);
Assert.AreEqual("\"200, 255, 13, 42\"", serialized);

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

0 comments on commit 52d9cf2

Please sign in to comment.