Get event handler type : Event « Reflection « C# / C Sharp






Get event handler type

  

using System;
using System.Reflection;
using System.Reflection.Emit;

public class Example
{
    private static object timer;

    public static void Main()
    {
        string fullName = "";
        foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
        {
            if (assem.GetName().Name == "mscorlib")
            {
                fullName = assem.FullName;
            }
        }
        Assembly sys = Assembly.Load("System" + fullName.Substring(fullName.IndexOf(",")));
        Type t = sys.GetType("System.Timers.Timer");
        timer = Activator.CreateInstance(t);

        EventInfo eInfo = t.GetEvent("Elapsed");
        Type handlerType = eInfo.EventHandlerType;
        MethodInfo invokeMethod = handlerType.GetMethod("Invoke");
        ParameterInfo[] parms = invokeMethod.GetParameters();
        Type[] parmTypes = new Type[parms.Length];
        for (int i = 0; i < parms.Length; i++)
        {
            parmTypes[i] = parms[i].ParameterType;
        }


   }
}

   
    
  








Related examples in the same category

1.Show Events
2.EventInfo Class discovers the attributes of an event and provides access to event metadata.
3.Use reflection to get the Elapsed event
4.EventInfo.EventHandlerType
5.Returns the EventInfo object representing the specified public event.
6.Returns the EventInfo object representing the specified event, using the specified binding constraints.
7.Search for events that are declared or inherited by the current Type, using the specified binding constraints.
8.Returns all the public events that are declared or inherited by the current Type.