EventInfo.EventHandlerType Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Overridable ReadOnly Property EventHandlerType As Type
public virtual Type EventHandlerType { get; }

Property Value

Type: System.Type
The delegate event handler.

Examples

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.

Imports System.Reflection

Public Delegate Sub MyDelegate(ByVal i As Integer, ByRef s As String)

Public Class Example
    Public Event MyEvent As MyDelegate

    Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

        Dim delegateType As Type = GetType(Example).GetEvent("MyEvent").EventHandlerType

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

        For Each p As ParameterInfo In invoke.GetParameters()
            outputBlock.Text &= p.ParameterType.ToString() & vbLf
        Next p
    End Sub 
End Class 

' This example produces the following output:
'
'System.Int32
'System.String&
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&
 */

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.