Type.GetMember 方法

定義

取得目前 Type 的指定成員。Gets the specified members of the current Type.

多載

GetMember(String)

搜尋具有指定名稱的公用成員。Searches for the public members with the specified name.

GetMember(String, BindingFlags)

使用指定的繫結條件約束搜尋指定的成員。Searches for the specified members, using the specified binding constraints.

GetMember(String, MemberTypes, BindingFlags)

使用指定的繫結條件約束,搜尋指定成員類型的指定成員。Searches for the specified members of the specified member type, using the specified binding constraints.

GetMember(String)

搜尋具有指定名稱的公用成員。Searches for the public members with the specified name.

public:
 virtual cli::array <System::Reflection::MemberInfo ^> ^ GetMember(System::String ^ name);
public System.Reflection.MemberInfo[] GetMember (string name);
abstract member GetMember : string -> System.Reflection.MemberInfo[]
override this.GetMember : string -> System.Reflection.MemberInfo[]
Public Function GetMember (name As String) As MemberInfo()

參數

name
String

字串,包含要取得的公用成員名稱。The string containing the name of the public members to get.

傳回

MemberInfo 物件的陣列,代表具有指定名稱的公用成員 (如有找到);否則為空陣列。An array of MemberInfo objects representing the public members with the specified name, if found; otherwise, an empty array.

實作

例外狀況

namenullname is null.

範例

下列範例會顯示以字母 C 為開頭之 String 類別的所有成員。The following example displays all the members of the String class that start with the letter C.

using namespace System;
using namespace System::Security;
using namespace System::Reflection;

// forward declarations:
void GetMemberInfo();
void GetPublicStaticMemberInfo();
void GetPublicInstanceMethodMemberInfo();
int main()
{
   try
   {
      GetMemberInfo();
      GetPublicStaticMemberInfo();
      GetPublicInstanceMethodMemberInfo();
   }
   catch ( ArgumentNullException^ e ) 
   {
      Console::WriteLine( "ArgumentNullException occurred." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }
   catch ( NotSupportedException^ e ) 
   {
      Console::WriteLine( "NotSupportedException occurred." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }
   catch ( SecurityException^ e ) 
   {
      Console::WriteLine( "SecurityException occurred." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception occurred." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }

}

void GetMemberInfo()
{
   String^ myString = "GetMember_String";
   Type^ myType = myString->GetType();
   
   // Get the members for myString starting with the letter C.
   array<MemberInfo^>^myMembers = myType->GetMember( "C*" );
   if ( myMembers->Length > 0 )
   {
      Console::WriteLine( "\nThe member(s) starting with the letter C for type {0}:", myType );
      for ( int index = 0; index < myMembers->Length; index++ )
         Console::WriteLine( "Member {0}: {1}", index + 1, myMembers[ index ] );
   }
   else
      Console::WriteLine( "No members match the search criteria." );
}

using System;
using System.Security;
using System.Reflection;

public class MyMemberSample 
{
    public static void Main()
    {
        MyMemberSample myClass = new MyMemberSample();
        try
        {
            myClass.GetMemberInfo();
            myClass.GetPublicStaticMemberInfo();	
            myClass.GetPublicInstanceMethodMemberInfo();	
        }      
        catch(ArgumentNullException e)
        {
            Console.WriteLine("ArgumentNullException occurred.");
            Console.WriteLine("Source: " + e.Source);
            Console.WriteLine("Message: " + e.Message);
        }
        catch(NotSupportedException e)
        {
            Console.WriteLine("NotSupportedException occurred.");
            Console.WriteLine("Source: " + e.Source);
            Console.WriteLine("Message: " + e.Message);
        }
        catch(SecurityException e)
        {
            Console.WriteLine("SecurityException occurred.");
            Console.WriteLine("Source: " + e.Source);
            Console.WriteLine("Message: " + e.Message);
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception occurred.");
            Console.WriteLine("Source: " + e.Source);
            Console.WriteLine("Message: " + e.Message);
        }
    }

    public void GetMemberInfo()
    {
        String myString = "GetMember_String";

        Type myType = myString.GetType();
        // Get the members for myString starting with the letter C.
        MemberInfo[] myMembers = myType.GetMember("C*");
        if(myMembers.Length > 0)
        {
            Console.WriteLine("\nThe member(s) starting with the letter C for type {0}:", myType);
            for(int index=0; index < myMembers.Length; index++)
                Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString());
        }
        else
        {
            Console.WriteLine("No members match the search criteria.");
        }
    }

Imports System.Security
Imports System.Reflection

Public Class MyMemberSample

    Public Shared Sub Main()
        Dim [myClass] As New MyMemberSample()
        Try
            [myClass].GetMemberInfo()
            [myClass].GetPublicStaticMemberInfo()
            [myClass].GetPublicInstanceMethodMemberInfo()
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException occurred.")
            Console.WriteLine(("Source: " + e.Source))
            Console.WriteLine(("Message: " + e.Message))
        Catch e As NotSupportedException
            Console.WriteLine("NotSupportedException occurred.")
            Console.WriteLine(("Source: " + e.Source))
            Console.WriteLine(("Message: " + e.Message))
        Catch e As SecurityException
            Console.WriteLine("SecurityException occurred.")
            Console.WriteLine(("Source: " + e.Source))
            Console.WriteLine(("Message: " + e.Message))
        Catch e As Exception
            Console.WriteLine("Exception occurred.")
            Console.WriteLine(("Source: " + e.Source))
            Console.WriteLine(("Message: " + e.Message))
        End Try
    End Sub


    Public Sub GetMemberInfo()
        Dim myString As [String] = "GetMember_String"
        Dim myType As Type = myString.GetType()
        ' Get the members for myString starting with the letter C.
        Dim myMembers As MemberInfo() = myType.GetMember("C*")
        If myMembers.Length > 0 Then
            Console.WriteLine(ControlChars.Cr + "The member(s) starting with the letter C for type {0}:", myType)
            Dim index As Integer
            For index = 0 To myMembers.Length - 1
                Console.WriteLine("Member {0}: {1}", index + 1, myMembers(index).ToString())
            Next index
        Else
            Console.WriteLine("No members match the search criteria.")
        End If
    End Sub

備註

name 的搜尋會區分大小寫。The search for name is case-sensitive. 搜尋包括公用靜態和公用實例成員。The search includes public static and public instance members.

成員包括屬性、方法、欄位、事件等。Members include properties, methods, fields, events, and so on.

GetMember 方法不會以特定順序傳回成員,例如依字母順序或宣告順序。The GetMember method does not return members in a particular order, such as alphabetical or declaration order. 您的程式碼不能相依于傳回成員的順序,因為該順序會有所不同。Your code must not depend on the order in which members are returned, because that order varies.

這個方法多載找不到類別初始化運算式(靜態的函數)。This method overload will not find class initializers (static constructor). 若要尋找類別初始化運算式,請使用接受 BindingFlags的多載, |並指定 BindingFlags.Static BindingFlags.NonPublicBindingFlags.StaticOrBindingFlags.NonPublic)。To find class initializers, use an overload that takes BindingFlags, and specify BindingFlags.Static | BindingFlags.NonPublic (BindingFlags.StaticOrBindingFlags.NonPublic in Visual Basic). 您也可以使用 TypeInitializer 屬性取得類別初始化運算式。You can also get the class initializer using the TypeInitializer property.

下表顯示當在類型上反映時,Get 方法傳回的基類成員。The following table shows what members of a base class are returned by the Get methods when reflecting on a type.

成員類型Member Type StaticStatic 非靜態Non-Static
建構函式Constructor No No
欄位Field No 可以。Yes. 欄位一律會依名稱和簽章隱藏。A field is always hide-by-name-and-signature.
Event - 事件Event 不適用Not applicable 一般類型系統規則是,繼承與實作為屬性的方法相同。The common type system rule is that the inheritance is the same as that of the methods that implement the property. 反映會將屬性視為逐名稱和簽章。Reflection treats properties as hide-by-name-and-signature. 請參閱下面的注2。See note 2 below.
方法Method No 可以。Yes. 方法(虛擬和非虛擬)可以依名稱或逐名稱和簽章來隱藏。A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.
巢狀型別Nested Type No No
屬性Property 不適用Not applicable 一般類型系統規則是,繼承與實作為屬性的方法相同。The common type system rule is that the inheritance is the same as that of the methods that implement the property. 反映會將屬性視為逐名稱和簽章。Reflection treats properties as hide-by-name-and-signature. 請參閱下面的注2。See note 2 below.
  1. [逐名稱] 和 [簽章] 會考慮簽章的所有部分,包括自訂修飾詞、傳回類型、參數類型、sentinels 和非受控呼叫慣例。Hide-by-name-and-signature considers all of the parts of the signature, including custom modifiers, return types, parameter types, sentinels, and unmanaged calling conventions. 這是二進位比較。This is a binary comparison.

  2. 針對反映,屬性和事件是依名稱和簽章來隱藏。For reflection, properties and events are hide-by-name-and-signature. 如果您在基類中具有具有 get 和 set 存取子的屬性,但衍生類別只有 get 存取子,則衍生類別屬性會隱藏基類屬性,而且您將無法存取基類上的 setter。If you have a property with both a get and a set accessor in the base class, but the derived class has only a get accessor, the derived class property hides the base class property, and you will not be able to access the setter on the base class.

  3. 自訂屬性不是一般型別系統的一部分。Custom attributes are not part of the common type system.

如果目前的 Type 代表結構化的泛型型別,這個方法會傳回 MemberInfo,其中的型別參數是由適當的型別引數所取代。If the current Type represents a constructed generic type, this method returns the MemberInfo with the type parameters replaced by the appropriate type arguments.

如果目前的 Type 表示泛型型別或泛型方法定義中的類型參數,則這個方法會搜尋類別條件約束的成員,或如果沒有類別條件約束,則為 Object 的成員。If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the members of the class constraint, or the members of Object if there is no class constraint.

注意

若為泛型方法,請勿在 name中包含型別引數。For generic methods, do not include the type arguments in name. 例如,程式C#代碼 GetMember("MyMethod<int>") 會搜尋名稱為 "MyMethod<int>" 的成員,而不是使用一個類型為 int之泛型引數的方法,而不是名為 MyMethod 的方法。For example, the C# code GetMember("MyMethod<int>") searches for a member with the text name "MyMethod<int>", rather than for a method named MyMethod that has one generic argument of type int.

另請參閱

GetMember(String, BindingFlags)

使用指定的繫結條件約束搜尋指定的成員。Searches for the specified members, using the specified binding constraints.

public:
 virtual cli::array <System::Reflection::MemberInfo ^> ^ GetMember(System::String ^ name, System::Reflection::BindingFlags bindingAttr);
public virtual System.Reflection.MemberInfo[] GetMember (string name, System.Reflection.BindingFlags bindingAttr);
abstract member GetMember : string * System.Reflection.BindingFlags -> System.Reflection.MemberInfo[]
override this.GetMember : string * System.Reflection.BindingFlags -> System.Reflection.MemberInfo[]
Public Overridable Function GetMember (name As String, bindingAttr As BindingFlags) As MemberInfo()

參數

name
String

字串,包含要取得的成員名稱。The string containing the name of the members to get.

bindingAttr
BindingFlags

列舉值的位元組合,用來指定搜尋的執行方式。A bitwise combination of the enumeration values that specify how the search is conducted.

-或--or- 要傳回空陣列的 DefaultDefault to return an empty array.

傳回

MemberInfo 物件的陣列,代表具有指定名稱的公用成員 (如有找到);否則為空陣列。An array of MemberInfo objects representing the public members with the specified name, if found; otherwise, an empty array.

實作

例外狀況

namenullname is null.

範例

下列範例會顯示以字母 C 開頭之 myString 類別的所有公用靜態成員。The following example displays all the public static members of the myString class that start with the letter C.

void GetPublicStaticMemberInfo()
{
   String^ myString = "GetMember_String_BindingFlag";
   Type^ myType = myString->GetType();
   
   // Get the public static members for the class myString starting with the letter C
   array<MemberInfo^>^myMembers = myType->GetMember( "C*", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static) );
   if ( myMembers->Length > 0 )
   {
      Console::WriteLine( "\nThe public static member(s) starting with the letter C for type {0}:", myType );
      for ( int index = 0; index < myMembers->Length; index++ )
         Console::WriteLine( "Member {0}: {1}", index + 1, myMembers[ index ] );
   }
   else
      Console::WriteLine( "No members match the search criteria." );
}
public void GetPublicStaticMemberInfo()
{
    String myString = "GetMember_String_BindingFlag";
    Type myType = myString.GetType();
    // Get the public static members for the class myString starting with the letter C.
    MemberInfo[] myMembers = myType.GetMember("C*",
        BindingFlags.Public |BindingFlags.Static);
    if(myMembers.Length > 0)
    {
        Console.WriteLine("\nThe public static member(s) starting with the letter C for type {0}:", myType);
        for(int index=0; index < myMembers.Length; index++)
            Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString());
    }
    else
    {
        Console.WriteLine("No members match the search criteria.");
    }
}
Public Sub GetPublicStaticMemberInfo()
    Dim myString As [String] = "GetMember_String_BindingFlag"

    Dim myType As Type = myString.GetType()
    ' Get the public static members for the class myString starting with the letter C.
    Dim myMembers As MemberInfo() = myType.GetMember("C*", BindingFlags.Public Or BindingFlags.Static)

    If myMembers.Length > 0 Then
        Console.WriteLine(ControlChars.Cr + "The public static member(s) starting with the letter C for type {0}:", myType)
        Dim index As Integer
        For index = 0 To myMembers.Length - 1
            Console.WriteLine("Member {0}: {1}", index + 1, myMembers(index).ToString())
        Next index
    Else
        Console.WriteLine("No members match the search criteria.")
    End If
End Sub

備註

衍生類別可以覆寫這個方法。This method can be overridden by a derived class.

成員包括屬性、方法、欄位、事件等。Members include properties, methods, fields, events, and so on.

GetMember 方法不會以特定順序傳回成員,例如依字母順序或宣告順序。The GetMember method does not return members in a particular order, such as alphabetical or declaration order. 您的程式碼不能相依于傳回成員的順序,因為該順序會有所不同。Your code must not depend on the order in which members are returned, because that order varies.

下列 BindingFlags 篩選準則旗標可用來定義要包含在搜尋中的成員:The following BindingFlags filter flags can be used to define which members to include in the search:

  • 您必須指定 BindingFlags.InstanceBindingFlags.Static,才能取得傳回。You must specify either BindingFlags.Instance or BindingFlags.Static in order to get a return.

  • 指定要在搜尋中包含公用成員 BindingFlags.PublicSpecify BindingFlags.Public to include public members in the search.

  • 指定要在搜尋中包含非公用成員(也就是私用、內部和受保護成員) BindingFlags.NonPublicSpecify BindingFlags.NonPublic to include non-public members (that is, private, internal, and protected members) in the search.

  • 指定 BindingFlags.FlattenHierarchy 在階層中包含 publicprotected 靜態成員;不包含繼承類別中 private 的靜態成員。Specify BindingFlags.FlattenHierarchy to include public and protected static members up the hierarchy; private static members in inherited classes are not included.

下列 BindingFlags 的修飾詞旗標可以用來變更搜尋的運作方式:The following BindingFlags modifier flags can be used to change how the search works:

  • BindingFlags.IgnoreCase 以忽略 name的大小寫。BindingFlags.IgnoreCase to ignore the case of name.

  • BindingFlags.DeclaredOnly 只搜尋 Type上宣告的成員,而不是直接繼承的成員。BindingFlags.DeclaredOnly to search only the members declared on the Type, not members that were simply inherited.

如需詳細資訊,請參閱 System.Reflection.BindingFlagsSee System.Reflection.BindingFlags for more information.

若要使用這個方法多載來取得類別初始化運算式(靜態的函式),您必須指定 name的「靜態|函式」,並 BindingFlags.Static BindingFlags.NonPublic (在 OrBindingFlags.StaticBindingFlags.NonPublic Visual Basic)以進行 bindingAttrTo get the class initializer (static constructor) using this method overload, you must specify "static constructor" for name, and BindingFlags.Static | BindingFlags.NonPublic (BindingFlags.StaticOrBindingFlags.NonPublic in Visual Basic) for bindingAttr. 您也可以使用 TypeInitializer 屬性取得類別初始化運算式。You can also get the class initializer using the TypeInitializer property.

如果目前的 Type 代表結構化的泛型型別,這個方法會傳回 MemberInfo,其中的型別參數是由適當的型別引數所取代。If the current Type represents a constructed generic type, this method returns the MemberInfo with the type parameters replaced by the appropriate type arguments.

如果目前的 Type 表示泛型型別或泛型方法定義中的類型參數,則這個方法會搜尋類別條件約束的成員,或如果沒有類別條件約束,則為 Object 的成員。If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the members of the class constraint, or the members of Object if there is no class constraint.

注意

若為泛型方法,請勿在 name中包含型別引數。For generic methods, do not include the type arguments in name. 例如,程式C#代碼 GetMember("MyMethod<int>") 會搜尋名稱為 "MyMethod<int>" 的成員,而不是使用一個類型為 int之泛型引數的方法,而不是名為 MyMethod 的方法。For example, the C# code GetMember("MyMethod<int>") searches for a member with the text name "MyMethod<int>", rather than for a method named MyMethod that has one generic argument of type int.

另請參閱

GetMember(String, MemberTypes, BindingFlags)

使用指定的繫結條件約束,搜尋指定成員類型的指定成員。Searches for the specified members of the specified member type, using the specified binding constraints.

public:
 virtual cli::array <System::Reflection::MemberInfo ^> ^ GetMember(System::String ^ name, System::Reflection::MemberTypes type, System::Reflection::BindingFlags bindingAttr);
public virtual System.Reflection.MemberInfo[] GetMember (string name, System.Reflection.MemberTypes type, System.Reflection.BindingFlags bindingAttr);
abstract member GetMember : string * System.Reflection.MemberTypes * System.Reflection.BindingFlags -> System.Reflection.MemberInfo[]
override this.GetMember : string * System.Reflection.MemberTypes * System.Reflection.BindingFlags -> System.Reflection.MemberInfo[]
Public Overridable Function GetMember (name As String, type As MemberTypes, bindingAttr As BindingFlags) As MemberInfo()

參數

name
String

字串,包含要取得的成員名稱。The string containing the name of the members to get.

type
MemberTypes

要搜尋的值。The value to search for.

bindingAttr
BindingFlags

列舉值的位元組合,用來指定搜尋的執行方式。A bitwise combination of the enumeration values that specify how the search is conducted.

-或--or- 要傳回空陣列的 DefaultDefault to return an empty array.

傳回

MemberInfo 物件的陣列,代表具有指定名稱的公用成員 (如有找到);否則為空陣列。An array of MemberInfo objects representing the public members with the specified name, if found; otherwise, an empty array.

實作

例外狀況

namenullname is null.

衍生類別必須提供實作。A derived class must provide an implementation.

範例

下列範例會顯示以字母 C 開頭之 myString 類別的所有方法。The following example displays all the methods of the myString class that start with the letter C.

void GetPublicInstanceMethodMemberInfo()
{
   String^ myString = "GetMember_String_MemberType_BindingFlag";
   Type^ myType = myString->GetType();
   
   // Get the public instance methods for myString starting with the letter C.
   array<MemberInfo^>^myMembers = myType->GetMember( "C*", MemberTypes::Method, static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance) );
   if ( myMembers->Length > 0 )
   {
      Console::WriteLine( "\nThe public instance method(s) starting with the letter C for type {0}:", myType );
      for ( int index = 0; index < myMembers->Length; index++ )
         Console::WriteLine( "Member {0}: {1}", index + 1, myMembers[ index ] );
   }
   else
      Console::WriteLine( "No members match the search criteria." );
}
    public void GetPublicInstanceMethodMemberInfo()
    {
        String myString = "GetMember_String_MemberType_BindingFlag";
        Type myType = myString.GetType();
        // Get the public instance methods for myString starting with the letter C.
        MemberInfo[] myMembers = myType.GetMember("C*", MemberTypes.Method, 
            BindingFlags.Public | BindingFlags.Instance);
        if(myMembers.Length > 0)
        {
            Console.WriteLine("\nThe public instance method(s) starting with the letter C for type {0}:", myType);
            for(int index=0; index < myMembers.Length; index++)
                Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString());
        }
        else
        {
            Console.WriteLine("No members match the search criteria.");
        }
    }
}
    Public Sub GetPublicInstanceMethodMemberInfo()
        Dim myString As [String] = "GetMember_String_MemberType_BindingFlag"

        Dim myType As Type = myString.GetType()
        ' Get the public instance methods for myString starting with the letter C.
        Dim myMembers As MemberInfo() = myType.GetMember("C*", MemberTypes.Method, BindingFlags.Public Or BindingFlags.Instance)
        If myMembers.Length > 0 Then
            Console.WriteLine(ControlChars.Cr + "The public instance method(s) starting with the letter C for type {0}:", myType)
            Dim index As Integer
            For index = 0 To myMembers.Length - 1
                Console.WriteLine("Member {0}: {1}", index + 1, myMembers(index).ToString())
            Next index
        Else
            Console.WriteLine("No members match the search criteria.")
        End If
    End Sub
End Class

備註

成員包括屬性、方法、欄位、事件等。Members include properties, methods, fields, events, and so on.

GetMember 方法不會以特定順序傳回成員,例如依字母順序或宣告順序。The GetMember method does not return members in a particular order, such as alphabetical or declaration order. 您的程式碼不能相依于傳回成員的順序,因為該順序會有所不同。Your code must not depend on the order in which members are returned, because that order varies.

下列 BindingFlags 篩選準則旗標可用來定義要包含在搜尋中的成員:The following BindingFlags filter flags can be used to define which members to include in the search:

  • 您必須指定 BindingFlags.InstanceBindingFlags.Static,才能取得傳回。You must specify either BindingFlags.Instance or BindingFlags.Static in order to get a return.

  • 指定要在搜尋中包含公用成員 BindingFlags.PublicSpecify BindingFlags.Public to include public members in the search.

  • 指定要在搜尋中包含非公用成員(也就是私用、內部和受保護成員) BindingFlags.NonPublicSpecify BindingFlags.NonPublic to include non-public members (that is, private, internal, and protected members) in the search.

  • 指定 BindingFlags.FlattenHierarchy 在階層中包含 publicprotected 靜態成員;不包含繼承類別中 private 的靜態成員。Specify BindingFlags.FlattenHierarchy to include public and protected static members up the hierarchy; private static members in inherited classes are not included.

下列 BindingFlags 的修飾詞旗標可以用來變更搜尋的運作方式:The following BindingFlags modifier flags can be used to change how the search works:

  • BindingFlags.IgnoreCase 以忽略 name的大小寫。BindingFlags.IgnoreCase to ignore the case of name.

  • BindingFlags.DeclaredOnly 只搜尋 Type上宣告的成員,而不是直接繼承的成員。BindingFlags.DeclaredOnly to search only the members declared on the Type, not members that were simply inherited.

如需詳細資訊,請參閱 System.Reflection.BindingFlagsSee System.Reflection.BindingFlags for more information.

若要使用這個方法多載來取得類別初始化運算式(靜態的函式),您必須指定 name的「靜態函式」、 | typeMemberTypes.Constructor,以及 BindingFlags.NonPublicBindingFlags.StaticBindingFlags.StaticOrBindingFlags.NonPublic Visual Basic)。bindingAttrTo get the class initializer (static constructor) using this method overload, you must specify "static constructor" for name, MemberTypes.Constructor for type, and BindingFlags.Static | BindingFlags.NonPublic (BindingFlags.StaticOrBindingFlags.NonPublic in Visual Basic) for bindingAttr. 您也可以使用 TypeInitializer 屬性取得類別初始化運算式。You can also get the class initializer using the TypeInitializer property.

如果目前的 Type 代表結構化的泛型型別,這個方法會傳回 MemberInfo,其中的型別參數是由適當的型別引數所取代。If the current Type represents a constructed generic type, this method returns the MemberInfo with the type parameters replaced by the appropriate type arguments.

如果目前的 Type 表示泛型型別或泛型方法定義中的類型參數,則這個方法會搜尋類別條件約束的成員,或如果沒有類別條件約束,則為 Object 的成員。If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the members of the class constraint, or the members of Object if there is no class constraint.

注意

若為泛型方法,請勿在 name中包含型別引數。For generic methods, do not include the type arguments in name. 例如,程式C#代碼 GetMember("MyMethod<int>") 會搜尋名稱為 "MyMethod<int>" 的成員,而不是使用一個類型為 int之泛型引數的方法,而不是名為 MyMethod 的方法。For example, the C# code GetMember("MyMethod<int>") searches for a member with the text name "MyMethod<int>", rather than for a method named MyMethod that has one generic argument of type int.

另請參閱

適用於