ServicePoint: Use DateTime.UtcNow internally, which avoids looking up the timezone...
[mono.git] / mcs / class / System / System.ComponentModel / BaseNumberConverter.cs
index 5519c24f5e066570314c0f7763180fcd4823773d..738150c4bfb90f7631f2d07b2d42329d8321b79a 100644 (file)
@@ -48,17 +48,12 @@ namespace System.ComponentModel
 
                public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
                {
-                       if (sourceType == typeof (string)) 
-                               return true;
-                       return base.CanConvertFrom (context, sourceType);
+                       return sourceType == typeof (string) || base.CanConvertFrom (context, sourceType);
                }
 
                public override bool CanConvertTo(ITypeDescriptorContext context, Type t)
                {
-                       if (t == typeof (string))
-                               return true;
-
-                       return base.CanConvertTo (context, t);
+                       return t.IsPrimitive || base.CanConvertTo (context, t);
                }
 
                public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
@@ -100,15 +95,11 @@ namespace System.ComponentModel
                        if (culture == null)
                                culture = CultureInfo.CurrentCulture;
 
-#if NET_2_0
                        if (destinationType == typeof (string) && value is IConvertible)
                                return ((IConvertible) value).ToType (destinationType, culture);
-#else
-                       if (destinationType == typeof (string) && value.GetType () == InnerType) {
-                               NumberFormatInfo numberFormatInfo = (NumberFormatInfo) culture.GetFormat (typeof (NumberFormatInfo));
-                               return ConvertToString (value, numberFormatInfo);
-                       }
-#endif
+
+                       if (destinationType.IsPrimitive)
+                               return Convert.ChangeType (value, destinationType, culture);
 
                        return base.ConvertTo (context, culture, value, destinationType);
                }