Merge pull request #9187 from RoosterDragon/field-saver-culture

Fix culture in FieldSaver for collections
This commit is contained in:
Pavel Penev
2015-09-02 15:14:42 +03:00

View File

@@ -66,11 +66,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))
{
@@ -81,14 +83,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();
@@ -102,12 +96,12 @@ namespace OpenRA
if (t.IsArray && t.GetArrayRank() == 1)
{
return ((Array)v).Cast<object>().JoinWith(", ");
return ((Array)v).Cast<object>().Select(FormatValue).JoinWith(", ");
}
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(HashSet<>))
{
return ((System.Collections.IEnumerable)v).Cast<object>().JoinWith(", ");
return ((System.Collections.IEnumerable)v).Cast<object>().Select(FormatValue).JoinWith(", ");
}
// This is only for documentation generation
@@ -153,7 +147,7 @@ namespace OpenRA
public static string FormatValue(object o, FieldInfo f)
{
return FormatValue(f.GetValue(o), f.FieldType);
return FormatValue(f.GetValue(o));
}
}
}