Exemple #1
0
 /// <summary>
 /// Converts the given value object to the specified type, using the specified context and culture information.
 /// </summary>
 /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context.</param>
 /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo"></see>. If null is passed, the current culture is assumed.</param>
 /// <param name="value">The <see cref="T:System.Object"></see> to convert.</param>
 /// <param name="destinationType">The <see cref="T:System.Type"></see> to convert the value parameter to.</param>
 /// <returns>An <see cref="System.Object"></see> that represents the converted value.</returns>
 /// <exception cref="System.ArgumentNullException">destinationType</exception>
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == null)
     {
         throw new ArgumentNullException(nameof(destinationType));
     }
     if (destinationType == UnderlyingType && NameableType.IsInstanceOfType(value))
     {
         return(value);
     }
     if (destinationType == typeof(InstanceDescriptor))
     {
         return(new InstanceDescriptor(NameableType.GetConstructor(new[] { UnderlyingType }), new[] { value }, true));
     }
     if (value == null)
     {
         if (destinationType == typeof(string))
         {
             return(string.Empty);
         }
     }
     else if (UnderlyingTypeConverter != null)
     {
         return(UnderlyingTypeConverter.ConvertTo(context, culture, value, destinationType));
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }