Пример #1
0
 public object ConvertBack(object value, Type sourceType, object parameter, CultureInfo culture)
 {
     if (value == null)
     {
         if (!DefaultValueConverter.AcceptsNull(sourceType))
         {
             CultureInfo invariantCulture = CultureInfo.InvariantCulture;
             string      str      = "ValueConverter can't convert Type {0}  to Type {1}";
             object[]    objArray = new object[] { "'null'", sourceType.ToString() };
             throw new InvalidOperationException(string.Format(invariantCulture, str, objArray));
         }
         value = null;
     }
     else
     {
         Type type = value.GetType();
         this.EnsureConverter(sourceType, type);
         if (this.converter == null)
         {
             CultureInfo cultureInfo = CultureInfo.InvariantCulture;
             string      str1        = "ValueConverter can't convert Type {0}  to Type {1}";
             object[]    objArray1   = new object[] { type.ToString(), sourceType.ToString() };
             throw new InvalidOperationException(string.Format(cultureInfo, str1, objArray1));
         }
         value = this.converter.ConvertBack(value, sourceType, parameter, culture);
     }
     return(value);
 }
Пример #2
0
 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());
 }
Пример #3
0
        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);
        }