PropertyInfo.GetConstantValue Method

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

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

public virtual Object GetConstantValue()

Return Value

Type: System.Object
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 null.

ExceptionCondition
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.

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. 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.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft