-
Notifications
You must be signed in to change notification settings - Fork 151
Contract for TypeConverter.ConvertFrom(object) #236
base: master
Are you sure you want to change the base?
Conversation
Should doesn't mean can never. The following is an example of getting the method to return null. Pathological, but possible. public class NullTypeConverter : TypeConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return null;
}
}
[TypeConverter(typeof(NullTypeConverter))]
public class MyNullClass
{
}
public static class Program
{
public static void Main()
{
/// Should print true
Console.WriteLine(TypeDescriptor.GetConverter(typeof(MyNullClass)).ConvertFrom("foo") == null);
}
} |
Is there any return point from this sort of problem to what was probably intended in the framework originally? From: Nathan Dykman [mailto:[email protected]] Should doesn't mean can never. The following is an example of getting the method to return null. Pathological, but possible. public class NullTypeConverter : TypeConverter {
} [TypeConverter(typeof(NullTypeConverter))] public class MyNullClass { } public static class Program {
} — |
According to the Microsoft Reference Source:
Thus in the following code,
So even if the framework intended |
As far as I can tell this is a valid contract, it doesn't appear that ConvertFrom should ever return null - it either successfully returns the conversion or throws a NotSupportedException