public object ConvertBack(object o, Type type, object parameter, CultureInfo culture) { if (o == null && DefaultValueConverter.AcceptsNull(this.sourceType)) { return(o); } if (o != null && this.sourceType.IsAssignableFrom(o.GetType())) { return(o); } if (this.sourceType != typeof(string)) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; string str = "ValueConverter can't convert Type {0} to Type {1}"; object[] objArray = new object[] { o.GetType().ToString(), this.sourceType.ToString() }; throw new InvalidOperationException(string.Format(invariantCulture, str, objArray)); } return(o.ToString()); }
private object ConvertHelper(object o, Type destinationType, CultureInfo culture, bool isForward) { object obj; bool flag = isForward ? !this.shouldConvertTo : !this.shouldConvertFrom; if (flag) { if (!flag || ((o == null || !destinationType.IsAssignableFrom(o.GetType())) && (o != null || !DefaultValueConverter.AcceptsNull(destinationType)))) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; string str = "ValueConverter can't convert Type {0} to Type {1}"; object[] objArray = new object[] { (o == null ? "'null'" : o.GetType().ToString()), destinationType.ToString() }; throw new InvalidOperationException(string.Format(invariantCulture, str, objArray)); } obj = o; flag = false; } else { obj = !isForward?this.typeConverter.ConvertFrom(o) : this.typeConverter.ConvertTo(o, destinationType); } return(obj); }