MemberTypes Énumération

Définition

Marque chaque type de membre qui est défini comme une classe dérivée de MemberInfo.

Cette énumération prend en charge une combinaison au niveau du bit de ses valeurs membres.

public enum class MemberTypes
[System.Flags]
public enum MemberTypes
[System.Flags]
[System.Serializable]
public enum MemberTypes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum MemberTypes
[<System.Flags>]
type MemberTypes = 
[<System.Flags>]
[<System.Serializable>]
type MemberTypes = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MemberTypes = 
Public Enum MemberTypes
Héritage
MemberTypes
Attributs

Champs

All 191

Spécifie tous les types de membres.

Constructor 1

Spécifie que le membre est un constructeur.

Custom 64

Spécifie que le membre est un type de membre personnalisé.

Event 2

Spécifie que le membre est un événement.

Field 4

Spécifie que le membre est un champ.

Method 8

Spécifie que le membre est une méthode.

NestedType 128

Spécifie que le membre est un type imbriqué.

Property 16

Spécifie que le membre est une propriété.

TypeInfo 32

Spécifie que le membre est un type.

Exemples

L’exemple suivant affiche les noms des membres de la ReflectionTypeLoadException classe et de leurs types de membres associés.

using namespace System;
using namespace System::Reflection;
 
void main() 
{
    // Get the type of a chosen class.
    Type^ t = ReflectionTypeLoadException::typeid;

    // Get the MemberInfo array.
    array<MemberInfo^>^ members = t->GetMembers();

    // Get and display the name and the MemberType for each member.
    Console::WriteLine("Members of {0}", t->Name);
    for each (MemberInfo^ 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
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
Imports System.Reflection

Module Example
    Public Sub Main()
        ' Get the type of a particular class.
        Dim t As Type = GetType(ReflectionTypeLoadException)

        ' Get the MemberInfo array.
        Dim members As MemberInfo() = t.GetMembers()

        ' Get and display the name and the MemberType for each member.
        Console.WriteLine("Members of {0}", t.Name)
        For Each member In members
            Dim memberType As MemberTypes = member.MemberType
            Console.WriteLine("   {0}: {1}", member.Name, memberType)
        Next
    End Sub
End Module
' 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

Remarques

Ces valeurs d’énumération sont retournées par les propriétés suivantes :

Pour obtenir la valeur d’un MemberTypes type :

  1. Obtenez un Type objet qui représente ce type.

  2. Récupérez la valeur de la Type.MemberType propriété.

Pour obtenir les MemberTypes valeurs des membres d’un type.:

  1. Obtenez un Type objet qui représente ce type.

  2. Récupérez le MemberInfo tableau qui représente les membres de ce type en appelant la Type.GetMembers méthode.

  3. Récupérez la valeur de la MemberInfo.MemberType propriété From pour chaque membre du tableau. Une switch instruction en C# ou Select Case dans Visual Basic est généralement utilisée pour traiter les types de membres.

MemberTypes correspond à CorTypeAttr comme défini dans le fichier corhdr.h.

S’applique à