Get Properties with BindingFlags : BindingFlags « Reflection « C# / C Sharp






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

1.Use BindingFlags Instance and NonPublic
2.Print Method Info: BindingFlags
3.Searches for the constructors defined for the current Type, using the specified BindingFlags.
4.GetConstructors(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance)
5.Using difference BindingFlags to get method
6.BindingFlags.Public | BindingFlags.Instance
7.BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly
8.Get Nested Types with BindingFlags