Get all the public members of the current Type in CSharp
Description
The following code shows how to get all the public members of the current Type.
Example
using System.Reflection;
using System;/* w w w .j a va 2 s. co m*/
class MyClass
{
public int myInt = 0;
public string myString = null;
public MyClass()
{
}
public void Myfunction()
{
}
}
class Type_GetMembers
{
public static void Main()
{
MyClass myObject = new MyClass();
MemberInfo[] myMemberInfo;
Type myType = myObject.GetType();
myMemberInfo = myType.GetMembers();
Console.WriteLine("\nThe members of class '{0}' are :\n", myType);
for (int i = 0; i < myMemberInfo.Length; i++)
{
Console.WriteLine("'{0}' is a {1}", myMemberInfo[i].Name, myMemberInfo[i].MemberType);
}
}
}
The code above generates the following result.