Uh oh!
There was an error while loading. Please reload this page.
Contract for TypeConverter.ConvertFrom(object) - #236
Conversation
Nathan Dykman (ndykman)
commented
Sep 4, 2015
Should doesn't mean can never. The following is an example of getting the method to return null. Pathological, but possible. publicclassNullTypeConverter:TypeConverter{publicoverrideobjectConvertFrom(ITypeDescriptorContextcontext,CultureInfoculture,objectvalue){returnnull;}}[TypeConverter(typeof(NullTypeConverter))]publicclassMyNullClass{}publicstaticclassProgram{publicstaticvoidMain(){/// Should print true Console.WriteLine(TypeDescriptor.GetConverter(typeof(MyNullClass)).ConvertFrom("foo")==null);}} |
Brett Shearer (brettshearer)
commented
Sep 5, 2015
Is there any return point from this sort of problem to what was probably intended in the framework originally? From: Nathan Dykman [mailto:notifications@github.com] 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 { } — |
Yaakov (yaakov-h)
commented
Sep 5, 2015
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