C# TypeInfo GetMembers(BindingFlags)

Description

TypeInfo GetMembers(BindingFlags) When overridden in a derived class, searches for the members defined for the current Type, using the specified binding constraints.

Syntax

TypeInfo.GetMembers(BindingFlags) has the following syntax.


public abstract MemberInfo[] GetMembers(
  BindingFlags bindingAttr
)

Parameters

TypeInfo.GetMembers(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 (BindingFlags.Default), to return an empty array.

Returns

TypeInfo.GetMembers(BindingFlags) method returns

Example


using System.Reflection;
using System;//w w  w .  j a  va 2 s .co m
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.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo