static bool TryConvert(ref object value, BindableProperty targetProperty, Type convertTo, bool toTarget) { if (value == null) { return(true); } if ((toTarget && targetProperty.TryConvert(ref value)) || (!toTarget && convertTo.IsInstanceOfType(value))) { return(true); } object original = value; try { value = Convert.ChangeType(value, convertTo, CultureInfo.InvariantCulture); return(true); } catch (Exception ex) when(ex is InvalidCastException || ex is FormatException || ex is OverflowException) { value = original; return(false); } }