I
Israel
I want to create a bunch of generic interfaces based on a enum but
they need to convert from an integer value to that enum. The goal is
to make type safe interfaces to non-type safe 3rd party interfaces
which only provide integers and documentation. I can use Convert to
go in the other direction but it doesn't seem to be clicking in my
head how to convert from an integer to some enum type - or force the
compiler to realize that the generic type MUST be an enum.
This is kind of what I’m thinking but you can’t declare that a type
derives from System.Enum:
class Class1<TType> where TType : System.Enum
{
public Class1(int value)
{
m_Value = (TType)value;
}
TType Value
{
get
{
return m_Value;
}
}
TType m_Value;
}
they need to convert from an integer value to that enum. The goal is
to make type safe interfaces to non-type safe 3rd party interfaces
which only provide integers and documentation. I can use Convert to
go in the other direction but it doesn't seem to be clicking in my
head how to convert from an integer to some enum type - or force the
compiler to realize that the generic type MUST be an enum.
This is kind of what I’m thinking but you can’t declare that a type
derives from System.Enum:
class Class1<TType> where TType : System.Enum
{
public Class1(int value)
{
m_Value = (TType)value;
}
TType Value
{
get
{
return m_Value;
}
}
TType m_Value;
}