What is the purpose of the public "value__" field that I can see in Reflector against my enum?
Asked Answered
H

1

7

I am looking at an enum I created in Reflector and there is a public integer field called "value__".

What is the purpose of this member?

A link or reference to a document is fine for an answer.

Googling is a pain because "value__" is returning hits for "value".

I have been searching for nearly an hour and only found the links below. Most of these are the same article on different sites. They all show how to access the member via reflection but none of them explain what the member is for.

UPDATE

The last link below discusses (at the bottom) that you can't use value__ as an enum value as it is reserverd but does not say why.

http://www.vijaymukhi.com/documents/books/csadv/chap3.htm

Compiler Error

error CS0076: The enumerator name 'value__' is reserved and cannot be used ... Only for an enum does it not allow us to use the reserved word value__ as it must be using the same word internally to keep track of the enum.

UPDATE 2

The link below is to the MSDN page that for the compiler error that also says "value__" is reserved. But still no joy an finding out what the member does....

http://msdn.microsoft.com/en-us/library/e3988xhs(v=vs.71).aspx

Hairstreak answered 6/3, 2011 at 22:47 Comment(1)
Not related to the question, but to only show google results containing value__, enclose it with double quotes.Libra
H
10

The JIT compiler needs a definition of a value type that describes its layout when it gets boxed. Most of them are baked into mscorlib, like System.Int32. The enum keyword lets you create a new value type. The compiler must thus provide a definition for it in the metadata. Which is what you are looking at. You'll see static fields for each enumeration member, used by ToString(). And one instance field name value__ that stores the enumeration value. Key point is that this only exists in the boxed version of an enum value.

Hypnotherapy answered 6/3, 2011 at 23:8 Comment(2)
Thank you for this. Do you happen to know which document this information is in? I have millions of questions like this.... Incidentally, I spotted the field when I was looking a my PE file in COFF Explorer when I was reading the article that you posted as an answer to my last question lol.Hairstreak
Never mind, I've found it. It's the ECMA-335 spec. I should have known that.Hairstreak

© 2022 - 2024 — McMap. All rights reserved.