Export (0) Print
Expand All

MethodInfo.MemberType Property

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;
   }
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft