Edit

Share via


MemberTypes Enum

Definition

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

This enumeration supports a bitwise combination of its member values.

C#
[System.Flags]
public enum MemberTypes
C#
[System.Flags]
[System.Serializable]
public enum MemberTypes
C#
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum MemberTypes
Inheritance
MemberTypes
Attributes

Fields

Name Value Description
Constructor 1

Specifies that the member is a constructor.

Event 2

Specifies that the member is an event.

Field 4

Specifies that the member is a field.

Method 8

Specifies that the member is a method.

Property 16

Specifies that the member is a property.

TypeInfo 32

Specifies that the member is a type.

Custom 64

Specifies that the member is a custom member type.

NestedType 128

Specifies that the member is a nested type.

All 191

Specifies all member types.

Examples

The following example displays the names of the members of the ReflectionTypeLoadException class and their associated member types.

C#
using System;
using System.Reflection;

class Example
{
    public static void Main()
    {
        // Get the type of a chosen class.
        Type t = typeof(ReflectionTypeLoadException);
 
        // Get the MemberInfo array.
        MemberInfo[] members = t.GetMembers();
 
        // Get and display the name and the MemberType for each member.
        Console.WriteLine("Members of {0}", t.Name);
        foreach (var member in members) { 
            MemberTypes memberType = member.MemberType; 
            Console.WriteLine("   {0}: {1}", member.Name, memberType);
        }
    }
}
// The example displays the following output:
//       Members of ReflectionTypeLoadException
//          get_Types: Method
//          get_LoaderExceptions: Method
//          GetObjectData: Method
//          get_Message: Method
//          get_Data: Method
//          GetBaseException: Method
//          get_InnerException: Method
//          get_TargetSite: Method
//          get_StackTrace: Method
//          get_HelpLink: Method
//          set_HelpLink: Method
//          get_Source: Method
//          set_Source: Method
//          ToString: Method
//          get_HResult: Method
//          GetType: Method
//          Equals: Method
//          GetHashCode: Method
//          GetType: Method
//          .ctor: Constructor
//          .ctor: Constructor
//          Types: Property
//          LoaderExceptions: Property
//          Message: Property
//          Data: Property
//          InnerException: Property
//          TargetSite: Property
//          StackTrace: Property
//          HelpLink: Property
//          Source: Property
//          HResult: Property

Remarks

These enumeration values are returned by the following properties:

To obtain the MemberTypes value for a type:

  1. Get a Type object that represents that type.

  2. Retrieve the value of the Type.MemberType property.

To get the MemberTypes values for the members of a type.:

  1. Get a Type object that represents that type.

  2. Retrieve the MemberInfo array that represents the members of that type by calling the Type.GetMembers method.

  3. Retrieve the value of the From the MemberInfo.MemberType property for each member in the array. A switch statement in C# or Select Case statement in Visual Basic is typically used to process member types.

MemberTypes matches CorTypeAttr as defined in the corhdr.h file.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.5, 1.6, 2.0, 2.1