From c03d8249bdd5c4b38a411580114a57c3b41f07bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Sat, 4 Nov 2017 17:57:24 +0100 Subject: [PATCH] add string to primType in binding SetValueByReflexion --- src/CompilerServices/CompilerServices.cs | 29 +++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 5409aa5e..827ee617 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -295,18 +295,25 @@ namespace Crow else if (miDest.MemberType == MemberTypes.Field) destType =(miDest as FieldInfo).FieldType; - if (value != null) { - if (destType == TObject)//TODO: check that test of destType is not causing problems - convertedVal = value; - else { - origType = value.GetType (); - if (destType.IsAssignableFrom (origType)) - convertedVal = Convert.ChangeType (value, destType); - else if (origType.IsPrimitive & destType.IsPrimitive) - convertedVal = GetConvertMethod (destType).Invoke (null, new Object[] { value }); - else - convertedVal = getImplicitOp (origType, destType).Invoke (value, null); + try { + if (value != null) { + if (destType == TObject)//TODO: check that test of destType is not causing problems + convertedVal = value; + else { + origType = value.GetType (); + if (destType.IsAssignableFrom (origType)) + convertedVal = Convert.ChangeType (value, destType); + else if (origType == typeof(string) & destType.IsPrimitive) + convertedVal = Convert.ChangeType(value, destType); + else if (origType.IsPrimitive & destType.IsPrimitive) + convertedVal = GetConvertMethod (destType).Invoke (null, new Object[] { value }); + else + convertedVal = getImplicitOp (origType, destType).Invoke (value, null); + } } + } catch (Exception ex) { + Debug.WriteLine (ex.ToString ()); + return; } if (miDest.MemberType == MemberTypes.Property) -- 2.47.3