[archived content]
Dfl /

Event handler parameter type contravariance was added to DFL 0.9.5. This allows you to specify different types as your event handler callback functions.

For example, TreeView's afterExpand event can use delegates of any of the following:

  • void handlername(Object sender, TreeViewEventArgs ea) As previously done
  • void handlername(TreeView sender, TreeViewEventArgs ea)
  • void handlername(Control sender, EventArgs ea)
  • And so on...

This is type contravariance and lets you specify any base class type.

There is a limitation: since some events are inherited from base classes, the events do not know about these derived types; for instance, Control's click event used through TreeView will not let you specify TreeView as the sender type.

Note: Function addHandlerExact was added to Event and it works like the old, non-contravariant Event.

Thanks to Tomasz "h3r3tic" Stachowiak for his template assistance for this feature.

Page last modified on May 31, 2007, at 10:48 AM