/// <summary>Attempts to convert an instance of <see cref="T:System.Windows.Size" /> to a specified type. </summary> /// <returns>The object that is created from the converted instance of <see cref="T:System.Windows.Size" />.</returns> /// <param name="context">Provides contextual information about a component.</param> /// <param name="culture">Culture-specific information that should be respected during conversion.</param> /// <param name="value">The instance of <see cref="T:System.Windows.Size" /> to convert.</param> /// <param name="destinationType">The type that this instance of <see cref="T:System.Windows.Size" /> is converted to.</param> /// <exception cref="T:System.NotSupportedException"> /// <paramref name="value" /> is null or is not an instance of <see cref="T:System.Windows.Size" />, or if the <paramref name="destinationType" /> is not one of the valid destination types.</exception> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType != null && value is Size) { Size size = (Size)value; if (destinationType == typeof(string)) { return(size.ConvertToString(null, culture)); } } return(base.ConvertTo(context, culture, value, destinationType)); }
/// <summary> /// ConvertTo - Attempt to convert an instance of Size to the given type /// </summary> /// <returns> /// The object which was constructoed. /// </returns> /// <exception cref="NotSupportedException"> /// A NotSupportedException is thrown if "value" is null or not an instance of Size, /// or if the destinationType isn't one of the valid destination types. /// </exception> /// <param name="context"> The ITypeDescriptorContext for this call. </param> /// <param name="culture"> The CultureInfo which is respected when converting. </param> /// <param name="value"> The object to convert to an instance of "destinationType". </param> /// <param name="destinationType"> The type to which this will convert the Size instance. </param> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType != null && value is Size) { Size instance = (Size)value; if (destinationType == typeof(string)) { // Delegate to the formatting/culture-aware ConvertToString method. #pragma warning suppress 6506 // instance is obviously not null return(instance.ConvertToString(null, culture)); } } // Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.) return(base.ConvertTo(context, culture, value, destinationType)); }