Export (0) Print
Expand All
Expand Minimize
0 out of 1 rated this helpful - Rate this topic

MemberTypes Enumeration

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)

[SerializableAttribute] 
[FlagsAttribute] 
[ComVisibleAttribute(true)] 
public enum MemberTypes
/** @attribute SerializableAttribute() */ 
/** @attribute FlagsAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum MemberTypes
SerializableAttribute 
FlagsAttribute 
ComVisibleAttribute(true) 
public enum MemberTypes
 Member nameDescription
Supported by the .NET Compact FrameworkAllSpecifies all member types. 
Supported by the .NET Compact FrameworkConstructorSpecifies that the member is a constructor, representing a ConstructorInfo member. Hexadecimal value of 0x01. 
Supported by the .NET Compact FrameworkCustomSpecifies that the member is a custom member type. Hexadecimal value of 0x40. 
Supported by the .NET Compact FrameworkEventSpecifies that the member is an event, representing an EventInfo member. Hexadecimal value of 0x02. 
Supported by the .NET Compact FrameworkFieldSpecifies that the member is a field, representing a FieldInfo member. Hexadecimal value of 0x04. 
Supported by the .NET Compact FrameworkMethodSpecifies that the member is a method, representing a MethodInfo member. Hexadecimal value of 0x08. 
Supported by the .NET Compact FrameworkNestedTypeSpecifies that the member is a nested type, extending MemberInfo
Supported by the .NET Compact FrameworkPropertySpecifies that the member is a property, representing a PropertyInfo member. Hexadecimal value of 0x10. 
Supported by the .NET Compact FrameworkTypeInfoSpecifies that the member is a type, representing a TypeInfo member. Hexadecimal value of 0x20. 

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.

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

using System;
using System.Reflection;
 
class membertypesenum 
{
    public static int Main(string[] args) 
    {
        Console.WriteLine ("\nReflection.MemberTypes");
        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; 
            Console.WriteLine("The member {0} of {1} is a {2}.", Mymemberinfo.Name, Mytype, Mymembertypes.ToString());
        }
        return 0;
    }
}

import System.*;
import System.Reflection.*;

class MemberTypesEnum
{   
    public static void main(String[] args)
    {
        Console.WriteLine("\nReflection.MemberTypes");
        MemberTypes myMemberTypes;

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

        // Get the MemberInfo array.
        MemberInfo myMemberInfoArray[] = myType.GetMembers();
        // Get and display the name and the MemberType for each member.
        for (int iCtr = 0; iCtr < myMemberInfoArray.length ; iCtr++) {
            MemberInfo myMemberInfo = myMemberInfoArray[iCtr];
            myMemberTypes = myMemberInfo.get_MemberType();
            Console.WriteLine("The member {0} of {1} is a {2}.", 
                myMemberInfo.get_Name(), myType, myMemberTypes.ToString());
        }
    } //main
} //MemberTypesEnum

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.