Type.GetMembers Method
.NET Framework 1.1
Gets the members (properties, methods, fields, events, and so on) of the current Type.
Overload List
Returns all the public members of the current Type.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function GetMembers() As MemberInfo()
[C#] public MemberInfo[] GetMembers();
[C++] public: MemberInfo* GetMembers() [];
[JScript] public function GetMembers() : MemberInfo[];
When overridden in a derived class, searches for the members defined for the current Type, using the specified binding constraints.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public MustOverride Function GetMembers(BindingFlags) As MemberInfo() Implements IReflect.GetMembers
[C#] public abstract MemberInfo[] GetMembers(BindingFlags);
[C++] public: virtual MemberInfo* GetMembers(BindingFlags) [] = 0;
[JScript] public abstract function GetMembers(BindingFlags) : MemberInfo[];
Example
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of GetMembers. For other examples that might be available, see the individual overload topics.
[Visual Basic] Class [MyClass] Public myInt As Integer = 0 Public myString As String = Nothing Public Sub New() End Sub 'New Public Sub Myfunction() End Sub 'Myfunction End Class '[MyClass] Class Type_GetMembers_BindingFlags Public Shared Sub Main() Try Dim MyObject As New [MyClass]() Dim myMemberInfo() As MemberInfo ' Get the type of the class 'MyClass'. Dim myType As Type = MyObject.GetType() ' Get the public instance members of the class 'MyClass'. myMemberInfo = myType.GetMembers((BindingFlags.Public Or BindingFlags.Instance)) Console.WriteLine(ControlChars.Cr + "The public instance members of class '{0}' are : " + ControlChars.Cr, myType) Dim i As Integer For i = 0 To myMemberInfo.Length - 1 ' Display name and type of the member of 'MyClass'. Console.WriteLine("'{0}' is a {1}", myMemberInfo(i).Name, myMemberInfo(i).MemberType) Next i Catch e As SecurityException Console.WriteLine(("SecurityException : " + e.Message.ToString())) End Try End Sub 'Main End Class 'Type_GetMembers_BindingFlags [C#] class MyClass { public int myInt = 0; public string myString = null; public MyClass() { } public void Myfunction() { } } class Type_GetMembers_BindingFlags { public static void Main() { try { MyClass MyObject = new MyClass(); MemberInfo [] myMemberInfo; // Get the type of the class 'MyClass'. Type myType = MyObject.GetType(); // Get the public instance members of the class 'MyClass'. myMemberInfo = myType.GetMembers(BindingFlags.Public|BindingFlags.Instance); Console.WriteLine( "\nThe public instance members of class '{0}' are : \n", myType); for (int i =0 ; i < myMemberInfo.Length ; i++) { // Display name and type of the member of 'MyClass'. Console.WriteLine( "'{0}' is a {1}", myMemberInfo[i].Name, myMemberInfo[i].MemberType); } } catch (SecurityException e) { Console.WriteLine("SecurityException : " + e.Message ); } } } [C++] __gc class MyClass { public: int* myInt; String* myString; MyClass() { } void Myfunction() { } }; int main() { try { MyClass* MyObject = new MyClass(); MemberInfo* myMemberInfo[]; // Get the type of the class 'MyClass'. Type* myType = MyObject->GetType(); // Get the public instance members of the class 'MyClass'. myMemberInfo = myType->GetMembers(static_cast<BindingFlags>(BindingFlags::Public|BindingFlags::Instance)); Console::WriteLine(S"\nThe public instance members of class '{0}' are : \n", myType); for (int i =0 ; i < myMemberInfo->Length ; i++) { // Display name and type of the member of 'MyClass'. Console::WriteLine(S"'{0}' is a {1}", myMemberInfo[i]->Name,__box( myMemberInfo[i]->MemberType)); } } catch (SecurityException* e) { Console::WriteLine(S"SecurityException : {0}", e->Message); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.