C# Type GetEvents(BindingFlags)

Description

Type 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

Type.GetEvents(BindingFlags) has the following syntax.


public abstract EventInfo[] GetEvents(
  BindingFlags bindingAttr
)

Parameters

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

Type.GetEvents(BindingFlags) method returns

Example

The following example obtains an array of EventInfo objects that match the specified binding flags, gets all the events for a Button class, and displays the event names.


//from  www .  ja  v a 2s  . com
using System;
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 »




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