Bagikan melalui


MemberTypes Enumeration

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

Marks each type of member that is defined as a derived class of MemberInfo.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

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

Syntax

'Declaration
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration MemberTypes
[FlagsAttribute]
[ComVisibleAttribute(true)]
public enum MemberTypes

Members

Member name Description
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Constructor Specifies that the member is a constructor, representing a ConstructorInfo member. Hexadecimal value of 0x01.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Event Specifies that the member is an event, representing an EventInfo member. Hexadecimal value of 0x02.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Field Specifies that the member is a field, representing a FieldInfo member. Hexadecimal value of 0x04.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Method Specifies that the member is a method, representing a MethodInfo member. Hexadecimal value of 0x08.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Property Specifies that the member is a property, representing a PropertyInfo member. Hexadecimal value of 0x10.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 TypeInfo Specifies that the member is a type, representing a TypeInfo member. Hexadecimal value of 0x20.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Custom Specifies that the member is a custom member type. Hexadecimal value of 0x40.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 NestedType Specifies that the member is a nested type, extending MemberInfo.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 All Specifies all member types.

Remarks

These enum values are returned by MemberType and are useful in switch statements. MemberTypes matches CorTypeAttr as defined in the corhdr.h file.

To obtain the MemberTypes value for a method:

  • First get a Type.

  • From the Type, get the MemberInfo array.

  • From the MemberInfo array, get the MemberType.

Examples

The following example displays the member types for the specified class.

Imports System.Reflection

Class Example

   Public Overloads Shared Function Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) As Integer
      outputBlock.Text &= ControlChars.Lf & "Reflection.MemberTypes" & vbCrLf
      Dim Mymembertypes As MemberTypes

      ' Get the type of a chosen class.
      Dim Mytype As Type = Type.GetType("System.Reflection.ReflectionTypeLoadException")

      ' Get the MemberInfo array.
      Dim Mymembersinfoarray As MemberInfo() = Mytype.GetMembers()

      ' Get and display the name and the MemberType for each member.
      Dim Mymemberinfo As MemberInfo
      For Each Mymemberinfo In Mymembersinfoarray
         Mymembertypes = Mymemberinfo.MemberType
         outputBlock.Text += String.Format("The member {0} of {1} is a {2}.", Mymemberinfo.Name, Mytype, Mymembertypes.ToString()) & vbCrLf
      Next Mymemberinfo
      Return 0
   End Function 'Main
End Class 'membertypesenum
using System;
using System.Reflection;

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

      // Get the type of a chosen class.
      Type Mytype = Type.GetType
          ("System.Reflection.ReflectionTypeLoadException");

      // Get the MemberInfo array.
      MemberInfo[] Mymembersinfoarray = Mytype.GetMembers();

      // Get and display the name and the MemberType for each member.
      foreach (MemberInfo Mymemberinfo in Mymembersinfoarray)
      {
         Mymembertypes = Mymemberinfo.MemberType;
         outputBlock.Text += String.Format("The member {0} of {1} is a {2}.", Mymemberinfo.Name, Mytype, Mymembertypes.ToString()) + "\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.

See Also

Reference