Get all the public events that are declared or inherited by the current Type in CSharp
Description
The following code shows how to get all the public events that are declared or inherited by the current Type.
Example
using System;/*from ww w . java2s. c om*/
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);
for (int index = 0; index < myEventsBindingFlags.Length; index++)
{
Console.WriteLine(myEventsBindingFlags[index].ToString());
}
}
}
The code above generates the following result.