From: Jean-Philippe Bruyère Date: Sat, 4 Nov 2017 16:57:24 +0000 (+0100) Subject: add string to primType in binding SetValueByReflexion X-Git-Tag: 0.6.0~19^2~3 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=c03d8249bdd5c4b38a411580114a57c3b41f07bb;p=jp%2Fcrow.git add string to primType in binding SetValueByReflexion --- 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)