From d11e60474a28067eea04a3053269ccfb87c29f98 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Fri, 28 Aug 2015 19:36:51 +0100 Subject: [PATCH] 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)); } } }