Get Properties with BindingFlags
using System;
using System.Reflection;
using System.Reflection.Emit;
public class MyTypeClass
{
public String MyProperty1
{
get
{
return "hello";
}
}
public String MyProperty2
{
get
{
return "hello";
}
}
protected String MyProperty3
{
get
{
return "hello";
}
}
}
public class TypeMain
{
public static void Main()
{
Type myType =(typeof(MyTypeClass));
PropertyInfo[] myPropertyInfo = myType.GetProperties(BindingFlags.Public|BindingFlags.Instance);
Console.WriteLine("The mumber of public properties is {0}.", myPropertyInfo.Length);
PropertyInfo[] myPropertyInfo1 = myType.GetProperties(BindingFlags.NonPublic|BindingFlags.Instance);
Console.WriteLine("The number of protected properties is {0}.", myPropertyInfo1.Length);
}
}
Related examples in the same category