❔ Which types should I use for this dictionary
I am making a command interpreter from a game, which the players can use via /command <parameters>, each command can have different parameters, and different types for each parameter.
The only necessary parameter is context, player can be any other type, for example a string.
So now I wanted to create a dictionary like { Player=PlayerConverter, Foo=FooConverter } which takes parameter type of the method, and converts it with the converter class from string to x.
So the issue is that I do not know which types I need in the dictionary
5 Replies
Mhm, so you're essentially re-inventing DI but for methods
I would do this using a
CommandHandler
style approach myselfcould you give me a small example?
use the attributes to build a keyed type map (string to Type), then resolve the correct type from a DI container aware of your domain (players etc), cast it to
ICommandHandler
, then just pass the context to the handler and you're donethanks! Ill give it a try
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.