I have an enumeration defined like:
public enum MyColor
{
red = 1,
white = 2,
blue = 3
}
From my datareader i have an value as valuetype System.Int16
In my businessobject i have a property Nullable<MyColor>
Using LoadProperty(), Doing TypeCoerce, it can't convert to the desired type.
Why?
Is this not supported or a missing Coercion?
I traced the code and at cnv.CanConvertFrom(valueType) it steps into the else statement.
cnv = "System.ComponentModel.EnumConverter"
desiredType = "MyNameSpace.MyColor"
valueType = "System.Int16"
value = "1"
catch
{
TypeConverter cnv = TypeDescriptor.GetConverter(desiredType);
if (cnv != null && cnv.CanConvertFrom(valueType))
return cnv.ConvertFrom(value);
else
throw;
}
I really don't know and i must use the type coercion since it's my generic mapper calling LoadProperty without knowing which type a property is.
I've no other option then converting it myself first before calling LoadProperty.
Why can't the EnumConverter convert from Int16 ?
Ok i know why:
http://msdn.microsoft.com/en-us/library/at9d6zbw.aspx
Copyright (c) Marimer LLC