What is the purpose of the public “value__” field that I can see in Reflector against my enum?

时间秒杀一切 提交于 2019-12-19 08:31:01

问题


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.

  • http://powershell.com/cs/forums/p/462/599.aspx

  • http://tfl09.blogspot.com/2008/12/enums-enum-values-and-powershell.html

  • C# function that accepts an Enum item and returns the enum value (not the index)

  • http://www.mail-archive.com/dotnet@discuss.develop.com/msg02431.html

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


回答1:


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.



来源:https://stackoverflow.com/questions/5214031/what-is-the-purpose-of-the-public-value-field-that-i-can-see-in-reflector-ag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!