I have multiple state classes that each implements an IState interface, defining the kinds of methods that can be called on each:
public interface IState
{
Type BanknoteInserted(Banknote banknoteInfo);
Type SwitchToggled(bool switchEnabled);
Type CardDataReceived(string track1Data, string track2Data, string track3Data);
}
I have a CurrentState property that changes to point to whichever current IState implementation that is loaded.
Separately (driven by hardware or user interactions), I have events that need to execute those methods on CurrentState. For threading simplicity and other reasons, those events are enqueued and processed in sequence in a background thread.
How can I refer to a particular interface method in my queue, such that I can "apply" the method to whatever class is currently set as CurrentState when that queue item is dequeued?
Each method call in the queue should be able to receive meaningful, typed method parameters (set at the time the item is enqueued).
The only option that I've been able to get working is to fall back on reflection and to insert tuples of (string methodName, object[] methodParameters) into my queue, but is that the best option? It feels like I should be able to use delegates for this.