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.StaticOr中的 BindingFlags.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 NoNo NoNo
字段Field NoNo 可以。Yes. 字段始终按名称和签名隐藏。A field is always hide-by-name-and-signature.
事件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 NoNo 可以。Yes. 方法(虚拟和非虚拟)可按名称隐藏或按名称和签名隐藏。A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.
嵌套类型Nested Type NoNo NoNo
属性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. 按名称和签名隐藏将考虑签名的所有部分,包括自定义修饰符、返回类型、参数类型、个 sentinel 和非托管调用约定。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 访问器,则派生类属性将隐藏基类属性,并且你将无法访问基类的资源库。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 表示构造泛型类型,则此方法将返回类型参数替换为相应类型参数的 MemberInfoIf 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- 若为 Default,则返回空数组。Default 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.StaticYou 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 忽略 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指定 "静态构造函数| ",并为 OrBindingFlags.Static BindingFlags.NonPublicBindingFlags.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 表示构造泛型类型,则此方法将返回类型参数替换为相应类型参数的 MemberInfoIf 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- 若为 Default,则返回空数组。Default 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.StaticYou 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 忽略 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.

若要使用此方法重载获取类初始值设定项(静态构造函数),必须为 BindingFlags.NonPublic 指定 name的 "静态构造函数"、type|的 MemberTypes.ConstructorBindingFlags.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 表示构造泛型类型,则此方法将返回类型参数替换为相应类型参数的 MemberInfoIf 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.

另请参阅

适用于