Ejemplo n.º 1
0
        // Token: 0x060074B6 RID: 29878 RVA: 0x002162F8 File Offset: 0x002144F8
        internal IValueConverter GetDefaultValueConverter(Type sourceType, Type targetType, bool targetToSource)
        {
            IValueConverter valueConverter = this._valueConverterTable[sourceType, targetType, targetToSource];

            if (valueConverter == null)
            {
                valueConverter = DefaultValueConverter.Create(sourceType, targetType, targetToSource, this);
                if (valueConverter != null)
                {
                    this._valueConverterTable.Add(sourceType, targetType, targetToSource, valueConverter);
                }
            }
            return(valueConverter);
        }
Ejemplo n.º 2
0
        // cache of default converters (so that all uses of string-to-int can
        // share the same converter)
        internal IValueConverter GetDefaultValueConverter(Type sourceType,
                                                          Type targetType,
                                                          bool targetToSource)
        {
            IValueConverter result = _valueConverterTable[sourceType, targetType, targetToSource];

            if (result == null)
            {
                result = DefaultValueConverter.Create(sourceType, targetType, targetToSource, this);
                if (result != null)
                {
                    _valueConverterTable.Add(sourceType, targetType, targetToSource, result);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        // Token: 0x060074D2 RID: 29906 RVA: 0x00216A6C File Offset: 0x00214C6C
        internal static IValueConverter Create(Type sourceType, Type targetType, bool targetToSource, DataBindEngine engine)
        {
            bool flag  = false;
            bool flag2 = false;

            if (sourceType == targetType || (!targetToSource && targetType.IsAssignableFrom(sourceType)))
            {
                return(DefaultValueConverter.ValueConverterNotNeeded);
            }
            if (targetType == typeof(object))
            {
                return(new ObjectTargetConverter(sourceType, engine));
            }
            if (sourceType == typeof(object))
            {
                return(new ObjectSourceConverter(targetType, engine));
            }
            if (SystemConvertConverter.CanConvert(sourceType, targetType))
            {
                return(new SystemConvertConverter(sourceType, targetType));
            }
            Type underlyingType = Nullable.GetUnderlyingType(sourceType);

            if (underlyingType != null)
            {
                sourceType = underlyingType;
                flag       = true;
            }
            underlyingType = Nullable.GetUnderlyingType(targetType);
            if (underlyingType != null)
            {
                targetType = underlyingType;
                flag2      = true;
            }
            if (flag || flag2)
            {
                return(DefaultValueConverter.Create(sourceType, targetType, targetToSource, engine));
            }
            if (typeof(IListSource).IsAssignableFrom(sourceType) && targetType.IsAssignableFrom(typeof(IList)))
            {
                return(new ListSourceConverter());
            }
            if (sourceType.IsInterface || targetType.IsInterface)
            {
                return(new InterfaceConverter(sourceType, targetType));
            }
            TypeConverter converter = DefaultValueConverter.GetConverter(sourceType);
            bool          flag3     = converter != null && converter.CanConvertTo(targetType);
            bool          flag4     = converter != null && converter.CanConvertFrom(targetType);

            if ((flag3 || targetType.IsAssignableFrom(sourceType)) && (!targetToSource || flag4 || sourceType.IsAssignableFrom(targetType)))
            {
                return(new SourceDefaultValueConverter(converter, sourceType, targetType, targetToSource && flag4, flag3, engine));
            }
            converter = DefaultValueConverter.GetConverter(targetType);
            flag3     = (converter != null && converter.CanConvertTo(sourceType));
            flag4     = (converter != null && converter.CanConvertFrom(sourceType));
            if ((flag4 || targetType.IsAssignableFrom(sourceType)) && (!targetToSource || flag3 || sourceType.IsAssignableFrom(targetType)))
            {
                return(new TargetDefaultValueConverter(converter, sourceType, targetType, flag4, targetToSource && flag3, engine));
            }
            return(null);
        }