Nyelv

MemberTypes Enumeráció

Definíció

Megjelöli azokat a tagtípusokat, amelyek a származtatott osztályként MemberInfovannak definiálva.

Ez a felsorolás támogatja a tagértékek bitenkénti kombinációját.

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
Öröklődés
MemberTypes
Attribútumok

Mezők

Name Érték Description
Constructor 1

Megadja, hogy a tag konstruktor-e.

Event 2

Megadja, hogy a tag esemény-e.

Field 4

Megadja, hogy a tag egy mező.

Method 8

Megadja, hogy a tag metódus-e.

Property 16

Azt adja meg, hogy a tag egy tulajdonság.

TypeInfo 32

Megadja, hogy a tag típus-e.

Custom 64

Megadja, hogy a tag egyéni tagtípus-e.

NestedType 128

Megadja, hogy a tag beágyazott típus-e.

All 191

Az összes tagtípust megadja.

Példák

Az alábbi példa az osztály tagjainak nevét és a ReflectionTypeLoadException hozzájuk tartozó tagtípusokat jeleníti meg.

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

Megjegyzések

Ezeket az enumerálási értékeket a következő tulajdonságok adják vissza:

Egy típus értékének MemberTypes lekérése:

  1. Type Szerezze be az adott típust képviselő objektumot.

  2. Kérje le a Type.MemberType tulajdonság értékét.

Egy típus tagjainak értékeinek lekérése MemberTypes :

  1. Type Szerezze be az adott típust képviselő objektumot.

  2. A metódus meghívásával kérje le az MemberInfo adott típus tagjait képviselő tömböt Type.GetMembers .

  3. Kérje le a Tömb minden egyes tagjának From MemberInfo.MemberType tulajdonságának értékét. A Visual Basic switch utasítása C# vagy Select Case utasítással általában tagtípusok feldolgozására szolgál.

MemberTypes a corhdr.h fájlban definiált CorTypeAttr értéknek felel meg.

A következőre érvényes: