I have a class with properties such as :
[TypeConverter(typeof(SomeNameEnumValueConvert))]
public Example ExampleName { get; set; }
In my Enum TypeConverter, I try to get the Enum name from a certain integer, because the source is reading from a table consisting of strings.
In the table, it is stored as e.g. "33" (so not the name), e.g. from
public enum Example
{
Off = 1,
On = 33,
Whatever = 7
}
Then here piece of my converter code:
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
var enumValue = Convert.ToInt32(value);
return (context.PropertyDescriptor.PropertyType) enumValue
}
However, it gives here that context is a variable, not a type. So I have tried various ways to get this to work but parallel to this I will post it here, maybe that speeds up retries. I have tried casting to Enum, casting to (enum)(object), casting via GetType, casting via Assembly get the specific type but none of this seems to work. Ergo how to convert to the underlying system type.