MethodInfo.MemberType Property

May 11, 2014

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

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

public override MemberTypes MemberType { get; }

Property Value

Type: System.Reflection.MemberTypes
A MemberTypes value indicating that this member is a method.

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

To get the MemberType property, first get the class Type. From the Type, get the MethodInfo. From the MethodInfo, get the MemberType.

The following example displays the type of the specified member.


using System;
using System.Reflection;

class Example
{
   public static int Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "Reflection.MethodInfo" + "\n";

      // Get the Type and MethodInfo.
      Type MyType = Type.GetType("System.Reflection.FieldInfo");
      MethodInfo Mymethodinfo = MyType.GetMethod("GetValue");
      outputBlock.Text += MyType.FullName + "." + Mymethodinfo.Name + "\n";

      // Get and display the MemberType property.
      MemberTypes Mymembertypes = Mymethodinfo.MemberType;


      if (MemberTypes.Constructor == Mymembertypes)
      {
         outputBlock.Text += "MemberType is of type All." + "\n";
      }
      else if (MemberTypes.Custom == Mymembertypes)
      {
         outputBlock.Text += "MemberType is of type Custom." + "\n";
      }
      else if (MemberTypes.Event == Mymembertypes)
      {
         outputBlock.Text += "MemberType is of type Event." + "\n";
      }
      else if (MemberTypes.Field == Mymembertypes)
      {
         outputBlock.Text += "MemberType is of type Field." + "\n";
      }
      else if (MemberTypes.Method == Mymembertypes)
      {
         outputBlock.Text += "MemberType is of type Method." + "\n";
      }
      else if (MemberTypes.Property == Mymembertypes)
      {
         outputBlock.Text += "MemberType is of type Property." + "\n";
      }
      else if (MemberTypes.TypeInfo == Mymembertypes)
      {
         outputBlock.Text += "MemberType is of type TypeInfo." + "\n";
      }

      return 0;
   }
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft