suppose I have an enum
[Flags] public enum E { zero = 0, one = 1 }
then I can write
E e; object o = 1; e = (E) o;
and it will work.
BUT if I try to do that at runtime, like
(o as IConvertible).ToType(typeof(E), null)
it will throw InvalidCastException.
So, is there something that I can invoke at runtime, and it will convert from int32 to enum, in the same way as if I wrote a cast as above?
1 Answer