FieldInfo.MemberType Property

July 28, 2014

Gets a value that indicates that this member is a field.

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

public override MemberTypes MemberType { get; }

Property Value

Type: System.Reflection.MemberTypes
A value that indicates that this member is a field.

ExceptionCondition
MethodAccessException

This member is invoked late-bound through mechanisms such as Type.InvokeMember.

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 each instance member of the Example class is a field and displays the result.


using System;
using System.Reflection;

// Make a field.
public class Example
{
   private string m_field = "a private field";

   public string Field   
   {
      get
      {
         return m_field;
      }
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "Reflection.FieldInfo\n\n";

      MemberInfo[] instanceMembers = 
         typeof(Example).GetMembers(BindingFlags.Public | BindingFlags.NonPublic | 
                                    BindingFlags.Instance);
      foreach( MemberInfo mi in instanceMembers )
      {
         if (mi.MemberType == MemberTypes.Field)
         {
            outputBlock.Text += String.Format("{0} is a field. <----\n", mi.Name);
         }
         else
         {
            outputBlock.Text += String.Format("{0} is not a field. \n", mi.Name);
         }
      }
   }
}

/* This example produces the following output:

Reflection.FieldInfo

get_Field is not a field. 
ToString is not a field. 
Equals is not a field. 
GetHashCode is not a field. 
GetType is not a field. 
Finalize is not a field. 
MemberwiseClone is not a field. 
.ctor is not a field. 
Field is not a field. 
m_field is a field. <----
 */


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft