System.ComponentModel.TypeConverter.ConvertTo C# (CSharp) Method

ConvertTo() public method

public ConvertTo ( object value, Type destinationType ) : object
value object
destinationType Type
return object
        public object ConvertTo(object value, Type destinationType) {
            return ConvertTo(null, null, value, destinationType);
        }

Same methods

TypeConverter::ConvertTo ( ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType ) : object

Usage Example

Beispiel #1
0
        private static object DoConversion(object value, Type toType, CultureInfo culture)
        {
            if ((value is IConvertible) || (value == null))
            {
                try
                {
                    return(System.Convert.ChangeType(value, toType, culture));
                }
                catch (Exception)
                {
                    return(DependencyProperty.UnsetValue);
                }
            }
            else
            {
                System.ComponentModel.TypeConverter typeConverter = TypeDescriptor.GetConverter(value);

                if (typeConverter.CanConvertTo(toType))
                {
                    return(typeConverter.ConvertTo(null, culture, value, toType));
                }
            }

            return(DependencyProperty.UnsetValue);
        }
All Usage Examples Of System.ComponentModel.TypeConverter::ConvertTo