FieldInfo.GetRawConstantValue 方法


由编译器返回与字段关联的文本值。Returns a literal value associated with the field by a compiler.

 virtual System::Object ^ GetRawConstantValue();
public virtual object GetRawConstantValue ();
abstract member GetRawConstantValue : unit -> obj
override this.GetRawConstantValue : unit -> obj
Public Overridable Function GetRawConstantValue () As Object


一个 Object,它包含与此字段关联的文本值。An Object that contains the literal value associated with the field. 如果文本值是一个元素值为零的类类型,则返回值为 nullIf the literal value is a class type with an element value of zero, the return value is null.


非托管元数据中的常数表不包含当前字段的常数值。The Constant table in unmanaged metadata does not contain a constant value for the current field.

值的类型不是公共语言规范 (CLS) 许可的类型。The type of the value is not one of the types permitted by the Common Language Specification (CLS). 请参阅 ECMA 第 II 部分规范,元数据逻辑格式:其他结构、签名中使用的元素类型。See the ECMA Partition II specification Metadata Logical Format: Other Structures, Element Types used in Signatures.

未设置该字段的常数值。The constant value for the field is not set.


此方法是为托管编译器和代码分析器的设计器提供的。This method is provided for designers of managed compilers and code analyzers.

此方法可用于执行上下文和仅反射上下文中。This method can be used in both the execution context and the reflection-only context.

在非托管元数据中,常量表用于存储字段、参数和属性的常量值。In unmanaged metadata, the Constant table is used to store constant values for fields, parameters, and properties. 常数信息不会直接影响运行时行为。Constant information does not directly influence runtime behavior. 导入元数据时,编译器会在编译时检查此信息。Compilers inspect this information, at compile time, when importing metadata. 如果使用,则常数的值嵌入到编译器发出的 Microsoft 中间语言(MSIL)流中。If used, the value of a constant is embedded in the Microsoft intermediate language (MSIL) stream the compiler emits. 在运行时,不能使用 MSIL 指令来访问常量表。There are no MSIL instructions that can be used to access the Constant table at run time.


有关常量值和常量表的详细信息,请参阅 ECMA Partition II 文档。For more information on constant values and the Constant table, see the ECMA Partition II documentation. 可联机获取该文档;请参阅 MSDN 上的 ECMA C# 和公共语言基础结构标准和 Ecma International 网站上的标准 ECMA-335 - 公共语言基础结构 (CLI)The documentation is available online; see ECMA C# and Common Language Infrastructure Standards on MSDN and Standard ECMA-335 - Common Language Infrastructure (CLI) on the Ecma International Web site.