Почему нет ограничений на EventHandler<TEventArgs>?
Я просто случайно выяснил (когда что-то скомпилировано, что я не думал, что скомпилируется), что EventHandler не ограничен типом System.EventArgs.
Вот встроенные документы:
#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);
}
Это несоответствие между документами и реализацией?
Я спрашиваю, потому что мне любопытно. Это не жалоба вообще.
1 ответ
Ограничение типа было удалено в.net 4.5.
Вот подпись.net 4.5. http://msdn.microsoft.com/en-us/library/db0etb8x%28v=vs.110%29.aspx
[SerializableAttribute]
public delegate void EventHandler<TEventArgs>(
Object sender,
TEventArgs e
)
Вот подпись.net 4.0. 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