I have a "dispatch map" defined as such:
private Dictionary<string, Func<DynamicEntity, DynamicEntity, IEnumerable<DynamicEntity>, string>> _messageProcessing;
This allows me to dispatch to different methods easily depending on the name of the DynamicEntity instance.
To avoid being hated by everyone who maintains the code forever more, is there any way of naming the parameters in the Func to give some clue to which DynamicEntity is which?
You can't do it with the built-in Func
types, but it's easy enough to create your own custom delegate type and use it in a similar way:
_messageProcessing.Add("input", (x, y, z) => "output");
_messageProcessing.Add("another", (x, y, z) => "example");
// ...
delegate string DispatchFunc(DynamicEntity first, DynamicEntity second,
IEnumerable<DynamicEntity> collection);
Dictionary<string, DispatchFunc> _messageProcessing;