C# Type GetMembers(BindingFlags)
Description
Type GetMembers(BindingFlags)
when overridden in a
derived class, searches for the members defined for the current Type, using
the specified binding constraints.
Syntax
Type.GetMembers(BindingFlags)
has the following syntax.
public abstract MemberInfo[] GetMembers(
BindingFlags bindingAttr
)
Parameters
Type.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
Type.GetMembers(BindingFlags)
method returns
Example
The following code example demonstrates how to use the GetMembers(BindingFlags) method overload to collect information about all public instance members of a specified class.
using System;//from w w w. j a v a 2 s. c o m
using System.Reflection;
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);
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.