65.9K
CodeProject is changing. Read more.
Home

Global Event Distributor

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.50/5 (4 votes)

Dec 18, 2007

CPOL
viewsIcon

24273

downloadIcon

299

Global event handler distributor

Introduction

This articles discusses how to add event handlers by defining custom attributes on the event definitions and their handler methods.

Background

By using EventDistirbutor, you don't need to have references between the event and its handler method class.

Using the Code

Publish your event:

[PublishEvent("OnOver")]
public event EventHandler OnOver;

Subscribe to the event:

This must be public!

[SubscriberEvent("OnOver")]
public void OnOver(object sender, EventArgs e)
{
    Console.WriteLine("OnOver From Class A");
}

History

  • 18th December, 2007: Initial post