From 3ff57483ff8188215104b1d4f27de4a6800f1020 Mon Sep 17 00:00:00 2001 From: goyuken Date: Sun, 21 Dec 2014 05:56:51 +0000 Subject: [PATCH] tool manager: more config stuff --- BizHawk.Client.EmuHawk/tools/ToolManager.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index 7a7321ca92..f1a253b1b1 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.ComponentModel; using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Client.Common; @@ -217,14 +218,18 @@ namespace BizHawk.Client.EmuHawk object val; if (data.TryGetValue(prop.Name, out val)) { - try + if (val is string && prop.PropertyType != typeof(string)) { - prop.SetValue(tool, val, null); - } - catch - { - // FIXME + // if a type has a TypeConverter, and that converter can convert to string, + // that will be used in place of object markup by JSON.NET + + // but that doesn't work with $type metadata, and JSON.NET fails to fall + // back on regular object serialization when needed. so try to undo a TypeConverter + // operation here + var converter = TypeDescriptor.GetConverter(prop.PropertyType); + val = converter.ConvertFromString((string)val); } + prop.SetValue(tool, val, null); } }