Freigeben über


MethodInfo.MemberType Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Overrides ReadOnly Property MemberType As MemberTypes
public override MemberTypes MemberType { get; }

Property Value

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

Remarks

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.

Examples

The following example displays the type of the specified member.

Imports System.Reflection

Class Example

   Public Shared Function Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) As Integer
      outputBlock.Text &= "Reflection.MethodInfo" & vbCrLf

      ' Get the Type and MethodInfo.
      Dim MyType As Type = Type.GetType("System.Reflection.FieldInfo")
      Dim Mymethodinfo As MethodInfo = MyType.GetMethod("GetValue")
      outputBlock.Text &= MyType.FullName + "." + Mymethodinfo.Name & vbCrLf

      ' Get and display the MemberType property.
      Dim Mymembertypes As MemberTypes = Mymethodinfo.MemberType

      If MemberTypes.Constructor = Mymembertypes Then
         outputBlock.Text &= "MemberType is of type All." & vbCrLf

      ElseIf MemberTypes.Custom = Mymembertypes Then
         outputBlock.Text &= "MemberType is of type Custom." & vbCrLf

      ElseIf MemberTypes.Event = Mymembertypes Then
         outputBlock.Text &= "MemberType is of type Event." & vbCrLf

      ElseIf MemberTypes.Field = Mymembertypes Then
         outputBlock.Text &= "MemberType is of type Field." & vbCrLf

      ElseIf MemberTypes.Method = Mymembertypes Then
         outputBlock.Text &= "MemberType is of type Method." & vbCrLf

      ElseIf MemberTypes.Property = Mymembertypes Then
         outputBlock.Text &= "MemberType is of type Property." & vbCrLf

      ElseIf MemberTypes.TypeInfo = Mymembertypes Then
         outputBlock.Text &= "MemberType is of type TypeInfo." & vbCrLf

      End If
      Return 0
   End Function
End Class
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;
   }
}

Version Information

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

Platforms

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