This repository was archived by the owner on Jun 5, 2019. It is now read-only.
This repository was archived by the owner on Jun 5, 2019. It is now read-only.
Unboxing enums to underlying type #189
Open
Description
The same problem MF has:
Desktop CLR allows to unbox an enum into its underlying type and vice versa.
enum TestEnum { A }
static void Main(string[] args)
{
TestEnum test = TestEnum.A;
object obj = test;
int value = (int)obj;
// back
obj = value;
test = (TestEnum)obj;
}
This has been explicitly allowed by CLI specification up to the 3rd edition. Further discussion and less desired consequences at http://codeblog.jonskeet.uk/?p=91.
I do not feel strongly about allowing this (unlike in MF where I had a use case with resource enums), and I don't know if CoreCLR allows it, but it is a potential code compatibility issue to consider in the future.