Type.GetMember Type.GetMember Type.GetMember Type.GetMember Method

定義

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

多載

GetMember(String) GetMember(String) GetMember(String) GetMember(String)

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

GetMember(String, BindingFlags) GetMember(String, BindingFlags) GetMember(String, BindingFlags) GetMember(String, BindingFlags)

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

GetMember(String, MemberTypes, BindingFlags) GetMember(String, MemberTypes, BindingFlags) GetMember(String, MemberTypes, BindingFlags) GetMember(String, MemberTypes, BindingFlags)

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

GetMember(String) GetMember(String) GetMember(String) 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 String String 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.

實作

例外狀況

範例

下列範例顯示的所有成員String以字母 c 開頭的類別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
Imports System.Security
Imports System.Reflection
Imports Microsoft.VisualBasic

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 'Main


    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 'GetMemberInfo

備註

搜尋name會區分大小寫。The search for name is case-sensitive. 搜尋包含 public static 和 public 的執行個體成員。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.NonPublic (BindingFlags.Static Or BindingFlags.NonPublic Visual Basic 中)。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 和 unmanaged 呼叫慣例。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.

注意

如需泛型的方法,不包括中的型別引數nameFor generic methods, do not include the type arguments in name. 例如,C# 程式碼GetMember("MyMethod<int>")搜尋之成員的文字名稱 」MyMethod<int>",而不是方法,名為MyMethod具有一個泛型類型引數intFor 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) GetMember(String, BindingFlags) GetMember(String, BindingFlags) 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 String String String

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

bindingAttr
BindingFlags BindingFlags BindingFlags 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.

實作

例外狀況

範例

下列範例顯示的所有公用靜態成員myString以字母 c 開頭的類別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 'GetPublicStaticMemberInfo

備註

在衍生類別可以覆寫此方法。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.Public来包含在搜尋中的公用成員。Specify BindingFlags.Public to include public members in the search.

  • 指定BindingFlags.NonPublic要在搜尋中包含非公用成員 (也就是私用、 內部和受保護成員)。Specify 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 忽略大小寫的nameBindingFlags.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 (BindingFlags.Static Or BindingFlags.NonPublic Visual Basic 中) 的bindingAttr.To 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.

注意

如需泛型的方法,不包括中的型別引數nameFor generic methods, do not include the type arguments in name. 例如,C# 程式碼GetMember("MyMethod<int>")搜尋之成員的文字名稱 」MyMethod<int>",而不是方法,名為MyMethod具有一個泛型類型引數intFor 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) GetMember(String, MemberTypes, BindingFlags) GetMember(String, MemberTypes, BindingFlags) 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 String String String

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

type
MemberTypes MemberTypes MemberTypes MemberTypes

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

bindingAttr
BindingFlags BindingFlags BindingFlags 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.

實作

例外狀況

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

範例

下列範例顯示的所有方法myString以字母 c 開頭的類別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 'GetPublicInstanceMethodMemberInfo 
End Class 'MyMemberSample

備註

成員包含屬性、 方法、 欄位、 事件等等。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.Public来包含在搜尋中的公用成員。Specify BindingFlags.Public to include public members in the search.

  • 指定BindingFlags.NonPublic要在搜尋中包含非公用成員 (也就是私用、 內部和受保護成員)。Specify 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 忽略大小寫的nameBindingFlags.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.

若要取得使用這個方法多載類別初始設定式 (靜態建構函式),您必須指定 「 靜態建構函式 」 nameMemberTypes.Constructor for type,以及BindingFlags.Static | BindingFlags.NonPublic (BindingFlags.Static OrBindingFlags.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.

注意

如需泛型的方法,不包括中的型別引數nameFor generic methods, do not include the type arguments in name. 例如,C# 程式碼GetMember("MyMethod<int>")搜尋之成員的文字名稱 」MyMethod<int>",而不是方法,名為MyMethod具有一個泛型類型引數intFor 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.

另請參閱

適用於