I am attempting to subscribe delegates to an event held in a List<KeyValuePair<KeyEnum, Delegate>
The goal is to associate a series of Handlers to keyboard keys and named axes, both of which are represented by Enums
Dispatching is fairly easy, I just iterate over the list of KVPs, check a condition, and if the condition is met, call the delegate simply with member.Value;
I haven't encountered any issues with efficiency in processor time with this, and in fact, have found that it's significantly cleaner on the stack.
The issue is adding to the delegates after instantiated. Attempting to access it with collection.FirstOrDefault(n=>n.Key == KeyEnum.W).Value+= SomeMethod
doesn't work, as Value
is read only.
Is there a way to do this that doesn't require creating a new KeyValuePair
every time, or a better solution than KeyValuePair
in general