/// <summary> /// /// </summary> /// <param name="sourceType">The native or DataContext type from a string representation. The GenericType parameter: T is this type. </param> /// <returns></returns> private TFromStringDelegate GetTheTFromStringDelegateInt(Type sourceType, Type propertyType) { // IsConvert is performed when going from native (or T) to string. MethodInfo methInfoGetProp = GMT_TYPE.GetMethod("GetTfromString", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(sourceType); TFromStringDelegate result = (TFromStringDelegate)Delegate.CreateDelegate(typeof(TFromStringDelegate), methInfoGetProp); return(result); }
// Value is a string, we need to create a native object. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { #if DEBUG TwoTypes tt = FromMkUpExtParam(parameter, typeof(string)); if (tt.IsEmpty) { throw new InvalidOperationException("Type information was not available."); } // Check to see if the specified type is compatible with the type of the property the converter is asking for. if (!targetType.IsAssignableFrom(tt.SourceType)) { System.Diagnostics.Debug.WriteLine("The SourceType specified by the binding is not compatible with the TargetType on ConvertBack (PropFactoryValueConverter."); } if (value == null && !targetType.IsValueType) { return(null); } //System.Diagnostics.Debug.Assert(value == null || typeof(string).IsAssignableFrom(value.GetType()), $"PropFactory expected string input on convert back, but type was {value.GetType()}."); //if (targetType == typeof(object)) return value; #else if (value == null && !targetType.IsValueType) { return(null); } if (targetType == typeof(object)) { return(value); } //System.Diagnostics.Debug.Assert(value == null || typeof(string).IsAssignableFrom(value.GetType()), $"PropFactory expected string input on convert back, but type was {value.GetType()}."); TwoTypes tt = TwoTypes.FromMkUpExtParam(parameter, typeof(string)); if (tt.IsEmpty) { throw new InvalidOperationException("Type information was not available."); } #endif if (value == null) { if (targetType.IsValueType) { return(GetDefaultValue(targetType, "ConvertBackOp")); } } else { Type sourceRunTimeType = value?.GetType(); if (sourceRunTimeType != tt.SourceType) { if (sourceRunTimeType != typeof(string)) { throw new NotImplementedException("Converting from a type other than a string is not yet supported."); } TFromStringDelegate del = _converter.GetTheTFromStringDelegate(tt.SourceType, tt.DestType); string s = value as string; return(del(s)); } } return(value); }