导出 (0) 打印
全部展开
EN
此内容没有您的语言版本,但有英语版本。

Type.GetMember Method

Gets the specified members of the current Type.

Overload List

Searches for the members with the specified name.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetMember(String) As MemberInfo()
[C#] public MemberInfo[] GetMember(string);
[C++] public: MemberInfo* GetMember(String*) [];
[JScript] public function GetMember(String) : MemberInfo[];

Searches for the specified members, using the specified binding constraints.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function GetMember(String, BindingFlags) As MemberInfo() Implements IReflect.GetMember
[C#] public virtual MemberInfo[] GetMember(string, BindingFlags);
[C++] public: virtual MemberInfo* GetMember(String*, BindingFlags) [];
[JScript] public function GetMember(String, BindingFlags) : MemberInfo[];

Searches for the specified members of the specified member type, using the specified binding constraints.

[Visual Basic] Overloads Public Overridable Function GetMember(String, MemberTypes, BindingFlags) As MemberInfo()
[C#] public virtual MemberInfo[] GetMember(string, MemberTypes, BindingFlags);
[C++] public: virtual MemberInfo* GetMember(String*, MemberTypes, BindingFlags) [];
[JScript] public function GetMember(String, MemberTypes, BindingFlags) : MemberInfo[];

Example

[Visual Basic, C#, C++] The following example displays all the methods of the myString class that start with the letter C.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetMember. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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

[C#] 
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.");    
}
}

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Type Class | Type Members | System Namespace

显示:
© 2014 Microsoft