Windows apps
Collapse the table of content
Expand the table of content
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.

FieldInfo::FieldHandle Property

 

Gets a RuntimeFieldHandle, which is a handle to the internal metadata representation of a field.

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

public:
property RuntimeFieldHandle FieldHandle {
	virtual RuntimeFieldHandle get() abstract;
}

Property Value

Type: System::RuntimeFieldHandle

A handle to the internal metadata representation of a field.

The handles are valid only in the appdomain in which they were obtained.

The following example retrieves MyClass.MyField field information and displays the field associated with the field handle.

using namespace System;
using namespace System::Reflection;

public ref class MyClass
{
public:
   String^ MyField;
};

void DisplayFieldHandle( RuntimeFieldHandle myFieldHandle )
{
   // Get the type from the handle.
   FieldInfo^ myField = FieldInfo::GetFieldFromHandle( myFieldHandle );

   // Display the type.
   Console::WriteLine( "\nDisplaying the field from the handle.\n" );
   Console::WriteLine( "The type is {0}.", myField );
}

int main()
{
   MyClass^ myClass = gcnew MyClass;

   // Get the type of MyClass.
   Type^ myType = MyClass::typeid;
   try
   {
      // Get the field information of MyField.
      FieldInfo^ myFieldInfo = myType->GetField( "MyField", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance) );

      // Determine whether or not the FieldInfo Object* is 0.
      if ( myFieldInfo != nullptr )
      {
         // Get the handle for the field.
         RuntimeFieldHandle myFieldHandle = myFieldInfo->FieldHandle;
         DisplayFieldHandle( myFieldHandle );
      }
      else
      {
         Console::WriteLine( "The myFieldInfo Object* is 0." );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: {0}", e->Message );
   }
}

.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2017 Microsoft