From 4a75291140d3307837660dd1c09cb0d71717ea54 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Tue, 13 Oct 2020 08:32:38 +0200 Subject: [PATCH] C#: Output floats and doubles with InvariantCulture (#82) --- Il2CppInspector.Common/Reflection/Extensions.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Il2CppInspector.Common/Reflection/Extensions.cs b/Il2CppInspector.Common/Reflection/Extensions.cs index ad9d6c4..fafa44d 100644 --- a/Il2CppInspector.Common/Reflection/Extensions.cs +++ b/Il2CppInspector.Common/Reflection/Extensions.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -111,19 +112,19 @@ namespace Il2CppInspector.Reflection public static string ToCSharpValue(this object value, TypeInfo type, Scope usingScope = null) { if (value is bool) return (bool) value ? "true" : "false"; - if (value is float) + if (value is float f) return value switch { float.PositiveInfinity => "1F / 0F", float.NegativeInfinity => "-1F / 0F", float.NaN => "0F / 0F", - _ => value + "f" + _ => f.ToString(CultureInfo.InvariantCulture) + "f" }; - if (value is double) + if (value is double d) return value switch { double.PositiveInfinity => "1D / 0D", double.NegativeInfinity => "-1D / 0D", double.NaN => "0D / 0D", - _ => value.ToString() + _ => d.ToString(CultureInfo.InvariantCulture) }; if (value is string str) { return $"\"{str.ToEscapedString()}\"";