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. 搜索中包括公共 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 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
PropertyProperty 不适用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. 按名称和签名隐藏会考虑所有的签名,包括自定义修饰符,部分返回类型、 参数类型、 标记和非托管调用约定。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表示构造泛型类型,此方法返回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- 若为 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.

实现

异常

示例

下面的示例显示所有的公共静态成员的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- 若为 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.

实现

异常

派生类必须提供一个实现。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有关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.

另请参阅

适用于