Freigeben über


PropertyInfo.GetConstantValue Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Overridable Function GetConstantValue As Object
public virtual Object GetConstantValue()

Return Value

Type: System.Object
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 nulla null reference (Nothing in Visual Basic).

Exceptions

Exception Condition
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 Standard ECMA-335 - Common Language Infrastructure (CLI) specification, Partition II.

Remarks

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

NoteNote:

Calling this method might cause code to run in the assembly that provides the constant's type. Use the GetRawConstantValue method if you need to avoid running such code.

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 about constant values and the Constant table, see the ECMA Partition II documentation. 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.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 GetConstantValue is present but not supported in Silverlight for Windows Phone.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.