Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

PropertyInfo.GetConstantValue Method

Note: This method is new in the .NET Framework version 2.0.

Returns a literal value associated with the property by a compiler.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

public virtual Object GetConstantValue ()
public Object GetConstantValue ()
public function GetConstantValue () : Object

Return Value

An Object that contains the literal value associated with the property. If the literal value is a class type with an element value of zero, the return value is a null reference (Nothing in Visual Basic).

Exception typeCondition

InvalidOperationException

The Constant table in unmanaged metadata does not contain a constant value for the current property.

FormatException

The type of the value is not one of the types permitted by the Common Language Specification (CLS). See the ECMA Partition II specification, Metadata, 22.1.15.

This method is provided for designers of managed compilers and code analyzers.

NoteNote

Do not use this method in the reflection-only context, because it might cause code to execute. Use the GetRawConstantValue method instead.

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. If used, the value of a constant is embedded in the Microsoft intermediate language (MSIL) stream the compiler emits. There are no MSIL instructions that can be used to access the Constant table at run time.

NoteNote

For more information on constant values and the Constant table, see the ECMA Partition II documentation. Partition II documentation is available online at http://msdn.microsoft.com/net/ecma/ and http://www.ecma-international.org/publications/standards/Ecma-335.htm.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

Show:
© 2015 Microsoft