I need Something like
var enumConstants =
Enum.GetValues(enumType)
.Cast<Enum>()
.Select(x => ...);
as explained in this answer. But I get InvalidCastException
.
Update:
Sorry, the problem was somewhere else. I had something like:
var enumConstants =
Enum.GetValues(enumType)
.Cast<Enum>()
.Select(e => new SomeClass{Value = (int)Convert.ChangeType(e, e.GetTypeCode()), ...}).ToList();
and apparently Value = (int)Convert.ChangeType(e, e.GetTypeCode()
caused the problem. Which I don't know why.