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::MemberType Property

 

Gets a MemberTypes value indicating that this member is a field.

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

public:
property MemberTypes MemberType {
	virtual MemberTypes get() override;
}

Property Value

Type: System.Reflection::MemberTypes

A MemberTypes value indicating that this member is a field.

This property overrides MemberType. Therefore, when you examine a set of MemberInfo objects — for example, the array returned by GetMembers — the MemberType property returns MemberTypes::Field only when a given member is a field.

The following example determines whether the specified member is a field and displays the result.

using namespace System;
using namespace System::Reflection;

// Make a field.
public ref class Myfield
{
private:
   String^ field;

public:
   Myfield()
      : field( "a private field" )
   {}


   property String^ Field 
   {
      String^ get()
      {
         return field;
      }

   }

};

int main()
{
   Console::WriteLine( "\nReflection.FieldInfo" );
   Myfield^ myfield = gcnew Myfield;

   // Get the Type and FieldInfo.
   Type^ MyType = Type::GetType( "Myfield" );
   FieldInfo^ Myfieldinfo = MyType->GetField( "field", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );

   // Get and display the MemberType.
   Console::Write( "\n{0}.", MyType->FullName );
   Console::Write( "{0} - ", Myfieldinfo->Name );
   Console::Write( "{0};", myfield->Field );
   MemberTypes Mymembertypes = Myfieldinfo->MemberType;
   Console::Write( "MemberType is a {0}.", Mymembertypes );
   return 0;
}

This code produces the following output:

Reflection.FieldInfo

Myfield.field - a private field; MemberType is a Field

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2017 Microsoft