Imagine I have a C# app sitting on a server somewhere that is creating instances of the Item class and publishing them on a messaging service.
class Item
{
public int ID1, ID2, ID3;
public double Value1, Value2, Value3;
}
Now I have another C# app on a desktop somewhere listening to these messages. I want to be able to create callbacks based on specified values of the ID# fields. For example, “call this method whenever a message comes in where ID1 = 2, ID2 = 160, and ID3 = anything”. I think this would be straightforward if I used string key-value pairs, but ideally I could do this without giving up static typing. I imagine this requires reflection, but I’m not entirely sure where to start.
I’m picturing the app creating an instance of Item with the required ID# values (let’s say -1 means unspecified), and passing that into a RegisterCallback method of some object ItemListener. Then whenever ItemListener receives a new Item message, it can check for any callbacks that match, and act accordingly. Is this a reasonable design? Any suggestions on what to look at to implement it?
1 Answer