Permalink
Browse files

Minor improvement in error masking for type conversion

  • Loading branch information...
slodge committed Oct 6, 2013
1 parent 8a3c2c1 commit 219b9f37ea0db61a8e53954b6dabb50fd8410bca
Showing with 15 additions and 9 deletions.
  1. +15 −9 Cirrious/Cirrious.MvvmCross.Binding/ExtensionMethods/MvxBindingExtensions.cs
@@ -100,21 +100,27 @@ public static object MakeSafeValue(this Type propertyType, object value)
if (underlyingType == typeof(bool))
safeValue = value.ConvertToBoolean();
else
safeValue = Convert.ChangeType(value, underlyingType, CultureInfo.CurrentUICulture);
safeValue = ErrorMaskedConvert(value, underlyingType, CultureInfo.CurrentUICulture);
}
else
{
try
{
safeValue = Convert.ChangeType(value, propertyType, CultureInfo.CurrentUICulture);
}
catch (Exception)
{
// pokemon - mask the error
}
safeValue = ErrorMaskedConvert(value, propertyType, CultureInfo.CurrentUICulture);
}
}
return safeValue;
}
private static object ErrorMaskedConvert(object value, Type type, CultureInfo cultureInfo)
{
try
{
return Convert.ChangeType(value, type, cultureInfo);
}
catch (Exception)
{
// pokemon - mask the error
return value;
}
}
}
}

0 comments on commit 219b9f3

Please sign in to comment.