C# TypeInfo GetProperties(BindingFlags)

Description

TypeInfo GetProperties(BindingFlags) When overridden in a derived class, searches for the properties of the current Type, using the specified binding constraints.

Syntax

TypeInfo.GetProperties(BindingFlags) has the following syntax.


public abstract PropertyInfo[] GetProperties(
  BindingFlags bindingAttr
)

Parameters

TypeInfo.GetProperties(BindingFlags) has the following parameters.

  • bindingAttr - A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
  • bindingAttr - -or-
  • bindingAttr - Zero, to return null.

Returns

TypeInfo.GetProperties(BindingFlags) method returns

Example


using System;/*  w  ww.j av  a2s. c  o  m*/
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 number of public properties is {0}.", myPropertyInfo.Length);

        for(int i=0;i<myPropertyInfo.Length;i++)
        {
            PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo[i];
            Console.WriteLine("The property name is {0}.", myPropInfo.Name);
            Console.WriteLine("The property type is {0}.", myPropInfo.PropertyType);
        }
    }
}




















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo