EventHandlerType Property
Collapse the table of content
Expand the table of content

EventInfo.EventHandlerType Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the Type object of the underlying event-handler delegate associated with this event.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public virtual Type EventHandlerType { get; }

Property Value

Type: System.Type
The delegate event handler.

The following example uses the EventHandlerType property to discover the delegate type of an event and to display its parameter types.

The example defines a delegate named MyDelegate and an event named MyEvent of type MyDelegate. The code in the Main method discovers the event signature by getting the delegate type of the event, getting the Invoke method of the delegate type, and then retrieving and displaying the parameters.


using System;
using System.Reflection;

public delegate void MyDelegate(int i, ref string s);

public class Example
{
    public event MyDelegate MyEvent;

    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        Type delegateType = typeof(Example).GetEvent("MyEvent").EventHandlerType;

        // The Invoke method of a delegate type always has the same signature
        // as the delegate.
        MethodInfo invoke = delegateType.GetMethod("Invoke");

        foreach( ParameterInfo p in invoke.GetParameters() )
        {
            outputBlock.Text += p.ParameterType.ToString() + "\n";
        }
    }
}

/* This example produces the following output:

System.Int32
System.String&
 */


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft