Get members defined for the current Type using the specified binding constraints in CSharp
Description
The following code shows how to get members defined for the current Type using the specified binding constraints.
Example
using System.Reflection;
using System;/* w ww . ja va2 s .c om*/
class MyClass
{
public int myInt = 0;
public string myString = null;
public MyClass()
{
}
public void Myfunction()
{
}
}
class Type_GetMembers_BindingFlags
{
public static void Main()
{
MyClass MyObject = new MyClass();
MemberInfo[] myMemberInfo;
Type myType = MyObject.GetType();
myMemberInfo = myType.GetMembers(BindingFlags.Public | BindingFlags.Instance);
Console.WriteLine(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.