Click here to Skip to main content
15,886,077 members
Articles / Programming Languages / C#
Article

Global Event Distributor

Rate me:
Please Sign up or sign in to vote.
2.50/5 (4 votes)
18 Dec 2007CPOL 24K   8   2
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:

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

Subscribe to the event:

This must be public!

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

History

  • 18th December, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer QualiSystems
Israel Israel

Comments and Discussions

 
GeneralMore explaination would be good Pin
SleepyBoBos2-Jun-08 14:46
SleepyBoBos2-Jun-08 14:46 
Generalthanks for posting anyhow Pin
E. del Ayre19-Dec-07 14:56
E. del Ayre19-Dec-07 14:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.