From 30231964dba3f3daa80aa48a6b38ccb174d043cd Mon Sep 17 00:00:00 2001 From: CWX Date: Wed, 28 May 2025 18:54:07 +0100 Subject: [PATCH] Add culture Conversion with string to number converter, fixes strings with numbers and commas --- .../Json/Converters/StringToNumberFactoryConverter.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/StringToNumberFactoryConverter.cs b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/StringToNumberFactoryConverter.cs index 47a09d5e..a437cf7a 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/StringToNumberFactoryConverter.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/StringToNumberFactoryConverter.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; @@ -19,15 +20,15 @@ public class StringToNumberFactoryConverter : JsonConverterFactory private class StringToNumberConverter : JsonConverter { - private static readonly MethodInfo? stringParseMethod; + private static readonly MethodInfo? _stringParseMethod; static StringToNumberConverter() { // Do reflection only once to get parse - if (stringParseMethod == null) + if (_stringParseMethod == null) { var underlyingType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T); - stringParseMethod = underlyingType.GetMethod("Parse", [typeof(string)]); + _stringParseMethod = underlyingType.GetMethod("Parse", [typeof(string), typeof(IFormatProvider)]); } } @@ -46,9 +47,9 @@ public class StringToNumberFactoryConverter : JsonConverterFactory { var underlyingType = Nullable.GetUnderlyingType(typeToConvert) ?? typeToConvert; - if (stringParseMethod != null) + if (_stringParseMethod != null) { - return (T) stringParseMethod.Invoke(null, [value]); + return (T) _stringParseMethod.Invoke(null, [value, CultureInfo.CreateSpecificCulture("en-US")]); } } catch (Exception ex)