コード例 #1
0
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                object result;

                if (DefaultConverter.TryConvertTo(value, targetType, culture, m_converter, out result))
                {
                    return(result);
                }

                if (value != null)
                {
                    var valueType = value.GetType();

                    if (DefaultConverter.TryConvertTo(value, targetType, culture, TypeDescriptor.GetConverter(valueType), out result))
                    {
                        return(result);
                    }

                    if (targetType.IsAssignableFrom(valueType))
                    {
                        return(value);
                    }
                }
                else if (DefaultConverter.IsNullableType(targetType))
                {
                    return(value);
                }

                throw new ArgumentException("Cannot convert to type " + targetType.FullName + ".", "value");
            }