Last active
December 14, 2015 17:09
-
-
Save doctorpangloss/5120220 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Provide an argument to a "multiplexing" event | |
class EventDispatcher { | |
public delegate void EventHandler(MessageEvent e); | |
public event EventHandler MultiplexedEvent; | |
} | |
class MessageEvent { | |
int MessageType; // Guess what component I'm working on which does something very similar to this | |
object Data; | |
} | |
EventDispatcher dispatcher = new EventDispatcher(); | |
// Current semantics | |
dispatched.MultiplexedEvent += | |
(e) => Diagnostics.Trace.WriteLine(e.MessageType == 1 ? "Message type 1 handled." : "Message type 1 not received".); | |
dispatched.MultiplexedEvent += | |
(e) => Diagnostics.Trace.WriteLine(e.MessageType == 2 ? "Message type 2 handled." : "Message type 2 not received".); | |
// Desired semantics | |
dispatched.MultiplexedEvent(1) += (e) => Diagnostics.Trace.WriteLine("Message type 1 handled."); | |
dispatched.MultiplexedEvent(2) += (e) => Diagnostics.Trace.WriteLine("Message type 1 handled."); | |
// Of course it would be most awesome to do this, but I recognize it's really only possible in God's language, JavaScript | |
dispatched.MessageType1 += (e) => ... | |
dispatched.MessageType2 += (e) => ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually you can do that in c# using dynamic types, probably....