MemberTypes 列舉

定義

將所定義的每一種成員類型標記為 MemberInfo 的衍生類別。Marks each type of member that is defined as a derived class of MemberInfo.

此列舉有 FlagsAttribute 屬性,因此其成員值可進行位元組合。

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
繼承
MemberTypes
屬性

欄位

All 191

指定所有成員類型。Specifies all member types.

Constructor 1

指定成員為建構函式。Specifies that the member is a constructor.

Custom 64

指定成員為自訂成員類型。Specifies that the member is a custom member type.

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.

NestedType 128

指定成員為巢狀類型。Specifies that the member is a nested type.

Property 16

指定成員為屬性。Specifies that the member is a property.

TypeInfo 32

指定成員為類型。Specifies that the member is a type.

範例

下列範例會顯示類別成員的名稱 ReflectionTypeLoadException 及其相關聯的成員類型。The following example displays the names of the members of the ReflectionTypeLoadException class and their associated member types.

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

備註

下列屬性會傳回這些列舉值:These enumeration values are returned by the following properties:

若要取得 MemberTypes 類型的值:To obtain the MemberTypes value for a type:

  1. 取得 Type 代表該型別的物件。Get a Type object that represents that type.

  2. 取得屬性的值 Type.MemberTypeRetrieve the value of the Type.MemberType property.

取得型別 MemberTypes 成員的值。:To get the MemberTypes values for the members of a type.:

  1. 取得 Type 代表該型別的物件。Get a Type object that represents that type.

  2. MemberInfo 由呼叫方法,取得代表該類型之成員的陣列 Type.GetMembersRetrieve the MemberInfo array that represents the members of that type by calling the Type.GetMembers method.

  3. MemberInfo.MemberType針對陣列中每個成員的屬性,從屬性中取出的值。Retrieve the value of the From the MemberInfo.MemberType property for each member in the array. switchC # 中的語句或 Select Case Visual Basic 中的語句通常用來處理成員類型。A switch statement in C# or Select Case statement in Visual Basic is typically used to process member types.

MemberTypes 符合 corhdr.h .h 檔中所定義的 CorTypeAttr。MemberTypes matches CorTypeAttr as defined in the corhdr.h file.

適用於