C# TypeInfo GetEvents(BindingFlags)

Description

TypeInfo GetEvents(BindingFlags) When overridden in a derived class, searches for events that are declared or inherited by the current Type, using the specified binding constraints.

Syntax

TypeInfo.GetEvents(BindingFlags) has the following syntax.


public abstract EventInfo[] GetEvents(
  BindingFlags bindingAttr
)

Parameters

TypeInfo.GetEvents(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.GetEvents(BindingFlags) method returns

Example


using System;//from w  ww  .  j  a  v  a  2 s .c  o  m
using System.Reflection;
using System.Security;

class EventsSample
{
    public static void Main()
    { 
        BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public;  
        Type myTypeEvent = typeof(System.Windows.Forms.Button);
        EventInfo[] myEventsBindingFlags = myTypeEvent.GetEvents(myBindingFlags);
        Console.WriteLine("\nThe events on the Button class with the specified BindingFlags are:");
        for (int index = 0; index < myEventsBindingFlags.Length; index++)
        {
            Console.WriteLine(myEventsBindingFlags[index].ToString());
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo