diff --git a/OpenRA.Game/FieldLoader.cs b/OpenRA.Game/FieldLoader.cs index 4bacabc8b1..2cb685a30f 100644 --- a/OpenRA.Game/FieldLoader.cs +++ b/OpenRA.Game/FieldLoader.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Drawing; using System.Globalization; using System.Linq; @@ -374,6 +375,22 @@ namespace OpenRA return InvalidValueAction(value, fieldType, fieldName); } + else + { + var conv = TypeDescriptor.GetConverter(fieldType); + if (conv.CanConvertFrom(typeof(string))) + { + try + { + return conv.ConvertFromInvariantString(value); + } + catch + { + return InvalidValueAction(value, fieldType, fieldName); + } + } + } + UnknownFieldAction("[Type] {0}".F(value), fieldType); return null; } diff --git a/OpenRA.Game/FieldSaver.cs b/OpenRA.Game/FieldSaver.cs index 3c401870c7..50da9af1c7 100644 --- a/OpenRA.Game/FieldSaver.cs +++ b/OpenRA.Game/FieldSaver.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Drawing; using System.Globalization; using System.Linq; @@ -88,6 +89,19 @@ namespace OpenRA if (t == typeof(DateTime)) return ((DateTime)v).ToString("yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture); + // Try the TypeConverter + var conv = TypeDescriptor.GetConverter(t); + if (conv.CanConvertTo(typeof(string))) + { + try + { + return conv.ConvertToInvariantString(v); + } + catch + { + } + } + return v.ToString(); }