Created
January 3, 2010 01:50
-
-
Save chaliy/267772 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
TestEvents test = new TestEvents(); | |
var ff = new EventHandler<EventArgs>((s, e) => Console.WriteLine("Test")); | |
test.SomethingOccured += ff; | |
test.SomethingOccured += ff; | |
test.SomethingOccured -= ff; | |
test.FireSomethingOccured(); | |
} | |
public class TestEvents | |
{ | |
private readonly EventHandlerList _events = new EventHandlerList(); | |
private readonly static object SomethingOccuredEvent = new object(); | |
public event EventHandler<EventArgs> SomethingOccured | |
{ | |
add | |
{ | |
_events.AddHandler(SomethingOccuredEvent, value); | |
} | |
remove | |
{ | |
_events.RemoveHandler(SomethingOccuredEvent, value); | |
} | |
} | |
public void FireSomethingOccured() | |
{ | |
var somethingOccured = _events[SomethingOccuredEvent] as EventHandler<EventArgs>; | |
if (somethingOccured != null) | |
{ | |
somethingOccured(this, EventArgs.Empty); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment