Exemple #1
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var targetType = typeof(TTo);

            if (value == null)
            {
                return(RuntimeUtils.CreateDefaultValue(targetType));
            }

            var sourceType = value.GetType();

            return(PrimitiveConverterFactory.GetConverter(sourceType, targetType).Convert(value));
        }
Exemple #2
0
        private static DelegateConverter CreateXamlIValueConverter <TInput, TOutput>()
        {
            var directConverter  = PrimitiveConverterFactory.GetConverter <TInput, TOutput>();
            var reverseConverter = PrimitiveConverterFactory.GetConverter <TOutput, TInput>();

            if (directConverter == null || reverseConverter == null)
            {
                throw new Exception("Could not find appropriate converter");
            }

            return(new DelegateConverter((value, type) => SafeConverter(value, type, directConverter),
                                         (value, type) => SafeConverter(value, type, reverseConverter)));
        }
Exemple #3
0
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            var primitiveConverter = PrimitiveConverterFactory.GetConverter(sourceType, typeof(TTo));

            return(primitiveConverter != null);
        }