I am creating a class that will handle some I/O for various types of controls. To start out with, I’m using Serial or TCP sockets.
I’m trying to make this truly generic but have a question about how to restructure some events.
Serials and TCP Sockets have a DataAvailable event. In my code the DataAvailable event may be implemented in the UI or it may be implemented via an AddHandler directive. The thing is - when it gets to this new class - I don’t want to know where the DataAvailable event is implemented. I just want to temporarily implement it with a method in my class. Then when the operation of the class is done, I want to return the DataAvailable event handler to where it was previously.
Is there a way to do this? I can’t use AddHandler to add a new handler because you have to use RemoveHandler first and I don’t necessarily know the Handler’s method name or location.
I just want to temporarily substitute one method for another. It sounds like a good use of a Delegate, but I’ve never directly used Delegates before (with the exception of AddHanlder), and I don’t know if trying to use a Delegate will interfere with AddHandler or what.
So pointers are appreciated.