Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why no constraint on EventHandler<TEventArgs>?

I just figured out by accident (when something compiled that I didn't think would compile) that EventHandler is not constrained to the type System.EventArgs.

Here's the inline docs:

#region Assembly mscorlib.dll, v4.0.0.0
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll
#endregion

namespace System
{
    // Summary:
    //     Represents the method that will handle an event.
    //
    // Parameters:
    //   sender:
    //     The source of the event.
    //
    //   e:
    //     An System.EventArgs that contains the event data.
    //
    // Type parameters:
    //   TEventArgs:
    //     The type of the event data generated by the event.
    [Serializable]
    public delegate void EventHandler<TEventArgs>(object sender, TEventArgs e);
}

Is this a mismatch between docs and implementation?

I'm asking because I am curious. It's not a complaint at all.

like image 643
Aaron Anodide Avatar asked Apr 01 '13 02:04

Aaron Anodide


1 Answers

The type constraint was removed in .net 4.5.

Here is the .net 4.5 signature. http://msdn.microsoft.com/en-us/library/db0etb8x%28v=vs.110%29.aspx

[SerializableAttribute]
public delegate void EventHandler<TEventArgs>(
    Object sender,
    TEventArgs e
)

Here is the .net 4.0 signature. http://msdn.microsoft.com/en-us/library/db0etb8x%28v=vs.100%29.aspx

[SerializableAttribute]
public delegate void EventHandler<TEventArgs>(
    Object sender,
    TEventArgs e
)
where TEventArgs : EventArgs
like image 176
Will Avatar answered Nov 07 '22 10:11

Will