From 243763f5701a91790852c8666d571105ac03a6a2 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Fri, 28 Aug 2015 19:33:59 +0100 Subject: [PATCH 1/2] Remove redundant invariant culture handling for float, decimal, double. This is already handled by the type converter portion of the code. --- OpenRA.Game/FieldSaver.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/OpenRA.Game/FieldSaver.cs b/OpenRA.Game/FieldSaver.cs index 70b17ca936..bfeb669fa1 100644 --- a/OpenRA.Game/FieldSaver.cs +++ b/OpenRA.Game/FieldSaver.cs @@ -70,14 +70,6 @@ namespace OpenRA ((int)c.B).Clamp(0, 255)); } - // Don't save using country-specific decimal separators which can be misunderstood as group seperators. - if (t == typeof(float)) - return ((float)v).ToString(CultureInfo.InvariantCulture); - if (t == typeof(decimal)) - return ((decimal)v).ToString(CultureInfo.InvariantCulture); - if (t == typeof(double)) - return ((double)v).ToString(CultureInfo.InvariantCulture); - if (t == typeof(ImageFormat)) { return ((ImageFormat)v).ToString(); From d11e60474a28067eea04a3053269ccfb87c29f98 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Fri, 28 Aug 2015 19:36:51 +0100 Subject: [PATCH 2/2] Ensure the elements of arrays and sets are formatted correctly in FormatValue. We call FormatValue on each element to ensure correct culture and other formatting that would otherwise not be applied. --- OpenRA.Game/FieldSaver.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/FieldSaver.cs b/OpenRA.Game/FieldSaver.cs index bfeb669fa1..32a3775ddd 100644 --- a/OpenRA.Game/FieldSaver.cs +++ b/OpenRA.Game/FieldSaver.cs @@ -55,11 +55,13 @@ namespace OpenRA return new MiniYamlNode(field, FormatValue(o, o.GetType().GetField(field))); } - public static string FormatValue(object v, Type t) + public static string FormatValue(object v) { if (v == null) return ""; + var t = v.GetType(); + // Color.ToString() does the wrong thing; force it to format as an array if (t == typeof(Color)) { @@ -83,12 +85,12 @@ namespace OpenRA if (t.IsArray && t.GetArrayRank() == 1) { - return ((Array)v).Cast().JoinWith(", "); + return ((Array)v).Cast().Select(FormatValue).JoinWith(", "); } if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(HashSet<>)) { - return ((System.Collections.IEnumerable)v).Cast().JoinWith(", "); + return ((System.Collections.IEnumerable)v).Cast().Select(FormatValue).JoinWith(", "); } if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(OpenRA.Primitives.Cache<,>)) @@ -115,7 +117,7 @@ namespace OpenRA public static string FormatValue(object o, FieldInfo f) { - return FormatValue(f.GetValue(o), f.FieldType); + return FormatValue(f.GetValue(o)); } } }