//------------------------------------------------------ // // Private API // //------------------------------------------------------ private object ConvertHelper(object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, bool isForward) { object value = DependencyProperty.UnsetValue; bool needAssignment = (isForward ? !_shouldConvertTo : !_shouldConvertFrom); NotSupportedException savedEx = null; if (!needAssignment) { value = TryParse(o, destinationType, culture); if (value == DependencyProperty.UnsetValue) { ValueConverterContext ctx = Engine.ValueConverterContext; // The fixed VCContext object is usually available for re-use. // In the rare cases when a second conversion is requested while // a previous conversion is still in progress, we allocate a temporary // context object to handle the re-entrant request. if (ctx.IsInUse) { ctx = new ValueConverterContext(); } try { ctx.SetTargetElement(targetElement); if (isForward) { value = _typeConverter.ConvertTo(ctx, culture, o, destinationType); } else { value = _typeConverter.ConvertFrom(ctx, culture, o); } } catch (NotSupportedException ex) { needAssignment = true; savedEx = ex; } finally { ctx.SetTargetElement(null); } } } if (needAssignment && ((o != null && destinationType.IsAssignableFrom(o.GetType())) || (o == null && !destinationType.IsValueType))) { value = o; needAssignment = false; } if (TraceData.IsEnabled) { if ((culture != null) && (savedEx != null)) { TraceData.Trace(TraceEventType.Error, TraceData.DefaultValueConverterFailedForCulture( AvTrace.ToStringHelper(o), AvTrace.TypeName(o), destinationType.ToString(), culture), savedEx); } else if (needAssignment) { TraceData.Trace(TraceEventType.Error, TraceData.DefaultValueConverterFailed( AvTrace.ToStringHelper(o), AvTrace.TypeName(o), destinationType.ToString()), savedEx); } } if (needAssignment && savedEx != null) { throw savedEx; } return(value); }
//------------------------------------------------------ // // Private API // //------------------------------------------------------ private object ConvertHelper(object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, bool isForward) { object value = DependencyProperty.UnsetValue; bool needAssignment = (isForward ? !_shouldConvertTo : !_shouldConvertFrom); NotSupportedException savedEx = null; if (!needAssignment) { value = TryParse(o, destinationType, culture); if (value == DependencyProperty.UnsetValue) { ValueConverterContext ctx = Engine.ValueConverterContext; // The fixed VCContext object is usually available for re-use. // In the rare cases when a second conversion is requested while // a previous conversion is still in progress, we allocate a temporary // context object to handle the re-entrant request. (See Dev10 bugs // 809846 and 817353 for situations where this can happen.) if (ctx.IsInUse) { ctx = new ValueConverterContext(); } try { ctx.SetTargetElement(targetElement); if (isForward) { value = _typeConverter.ConvertTo(ctx, culture, o, destinationType); } else { value = _typeConverter.ConvertFrom(ctx, culture, o); } } catch (NotSupportedException ex) { needAssignment = true; savedEx = ex; } finally { ctx.SetTargetElement(null); } } } if (needAssignment && ( (o != null && destinationType.IsAssignableFrom(o.GetType())) || (o == null && !destinationType.IsValueType) )) { value = o; needAssignment = false; } if (TraceData.IsEnabled) { if ((culture != null) && (savedEx != null)) { TraceData.Trace(TraceEventType.Error, TraceData.DefaultValueConverterFailedForCulture( AvTrace.ToStringHelper(o), AvTrace.TypeName(o), destinationType.ToString(), culture), savedEx); } else if (needAssignment) { TraceData.Trace(TraceEventType.Error, TraceData.DefaultValueConverterFailed( AvTrace.ToStringHelper(o), AvTrace.TypeName(o), destinationType.ToString()), savedEx); } } if (needAssignment && savedEx != null) throw savedEx; return value; }
// Token: 0x060074D8 RID: 29912 RVA: 0x00216DAC File Offset: 0x00214FAC private object ConvertHelper(object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, bool isForward) { object obj = DependencyProperty.UnsetValue; bool flag = isForward ? (!this._shouldConvertTo) : (!this._shouldConvertFrom); NotSupportedException ex = null; if (!flag) { obj = DefaultValueConverter.TryParse(o, destinationType, culture); if (obj == DependencyProperty.UnsetValue) { ValueConverterContext valueConverterContext = this.Engine.ValueConverterContext; if (valueConverterContext.IsInUse) { valueConverterContext = new ValueConverterContext(); } try { valueConverterContext.SetTargetElement(targetElement); if (isForward) { obj = this._typeConverter.ConvertTo(valueConverterContext, culture, o, destinationType); } else { obj = this._typeConverter.ConvertFrom(valueConverterContext, culture, o); } } catch (NotSupportedException ex2) { flag = true; ex = ex2; } finally { valueConverterContext.SetTargetElement(null); } } } if (flag && ((o != null && destinationType.IsAssignableFrom(o.GetType())) || (o == null && !destinationType.IsValueType))) { obj = o; flag = false; } if (TraceData.IsEnabled) { if (culture != null && ex != null) { TraceData.Trace(TraceEventType.Error, TraceData.DefaultValueConverterFailedForCulture(new object[] { AvTrace.ToStringHelper(o), AvTrace.TypeName(o), destinationType.ToString(), culture }), ex); } else if (flag) { TraceData.Trace(TraceEventType.Error, TraceData.DefaultValueConverterFailed(new object[] { AvTrace.ToStringHelper(o), AvTrace.TypeName(o), destinationType.ToString() }), ex); } } if (flag && ex != null) { throw ex; } return(obj); }