jeudi 30 mars 2017

Invoke Class Method using Reflection with different params in constructor?

Hello i am very new to c# reflection and i have the following problem.

I have a CommandDispatcher class that invokes a certain Command class that does something.

For now i use a switch to determinate what command to invoke.

i wanted to simplify the code by using reflection to invoke the right command and get rid of the switch for good.

But each command takes a certain service or more in its constructor. I don't want to change that part . I understand that if i had no services passed in the constructor the code would work fine.

So how can i invoke my commands with reflection when each command takes one or many services.

Here is an image for better understanding: The code with color indicators

I left the switch not commented out for easier reading.

Here is the code in pastebin: http://ift.tt/2ofr0A2

My search did not result in finding anything to solve my problem.





Aucun commentaire:

Enregistrer un commentaire