public virtual object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value,
Type destinationType)
{
- // context? culture?
+ // context?
if (destinationType == null)
throw new ArgumentNullException ("destinationType");
if (destinationType == typeof (string)) {
- if (value != null)
- return value.ToString();
- return String.Empty;
+ if (value == null)
+ return String.Empty;
+
+ if (culture != null)
+ return Convert.ToString (value, culture);
+
+ return value.ToString();
}
return GetConvertToException (value, destinationType);
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
+using System.Globalization;
using NUnit.Framework;
Assert.IsTrue (ex.Message.IndexOf (typeof (string).FullName) != -1, "#B6");
}
}
+
+ [Test]
+ public void ConvertToWithCulture ()
+ {
+ var culture = CultureInfo.CreateSpecificCulture ("sv-se");
+
+ var converter = TypeDescriptor.GetConverter (typeof (string));
+ Assert.AreEqual ("0,5", (string) converter.ConvertTo (null, culture, 0.5, typeof (string)));
+ }
-#if NET_2_0
public class FooConverter<T> : TypeConverter
{
}
{
Assert.IsNotNull (GetType ().GetProperty ("FooProperty").GetCustomAttributes (false));
}
-#endif
[ExpectedException (typeof (NullReferenceException))]
public void GetConvertToException_DestinationType_Null ()