C# Type GetProperties(BindingFlags)

Description

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

Syntax

Type.GetProperties(BindingFlags) has the following syntax.


public abstract PropertyInfo[] GetProperties(
  BindingFlags bindingAttr
)

Parameters

Type.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

Type.GetProperties(BindingFlags) method returns

Example

The following example creates two public properties and one protected property and displays information for the properties that match the specified binding constraints.


using System;//from  w w w.j  av  a2s.  c om
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);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version