]> O.S.I.I.S - jp/crow.git/commitdiff
add string to primType in binding SetValueByReflexion
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Nov 2017 16:57:24 +0000 (17:57 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Nov 2017 16:57:24 +0000 (17:57 +0100)
src/CompilerServices/CompilerServices.cs

index 5409aa5e7b2210ac63148d7459fe30ae8d941f6b..827ee6178b4667fdef2fb28ccb8154f26b8ab45f 100644 (file)
@@ -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)