C# TypeInfo GetEvent(String, BindingFlags)

Description

TypeInfo GetEvent(String, BindingFlags) When overridden in a derived class, returns the EventInfo object representing the specified event, using the specified binding constraints.

Syntax

TypeInfo.GetEvent(String, BindingFlags) has the following syntax.


public abstract EventInfo GetEvent(
  string name,
  BindingFlags bindingAttr
)

Parameters

TypeInfo.GetEvent(String, BindingFlags) has the following parameters.

  • name - The string containing the name of an event which is declared or inherited by the current Type.
  • 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.GetEvent(String, BindingFlags) method returns The object representing the specified event that is declared or inherited by the current Type, if found; otherwise, null.

Example


/*from w  w w .  j  av  a2  s  .c o  m*/
using System;
using System.Reflection;
using System.Security;

class MyEventExample
{
    public static void Main()
    {  
        BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
        Type myTypeBindingFlags = typeof(System.Windows.Forms.Button);
        EventInfo myEventBindingFlags = myTypeBindingFlags.GetEvent("Click", myBindingFlags);
        if(myEventBindingFlags != null)
        {
            Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags.");
            Console.WriteLine(myEventBindingFlags.ToString());
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo