0

I am trying to make a generic method about executing custom commands in MVC base system.

I have a method called DispatchCommand. I give that method to command type and command parameter type. My command type inherited from a MVCCommand<T1>

public class CreateEnvironmentsCommand : MVCCommand<LevelVO>

My dispatch command method is like that,

IMVCCommand<T1> DispatchCommand<TCommand, T1>() where TCommand : IMVCCommand<T1>, new()

When I want to run this method I need to give CommandType and Command Generic Parameter Type for example:

DispatchCommand<CreateEnvironmentsCommand, LevelVO>();

But my command already included LevelVO type in itself. Is there a way to call this method like this:

DispatchCommand<CreateEnvironmentsCommand>();

Sorry for my english...

Umutcan Ertürk
  • 155
  • 1
  • 3
  • 11
  • It's a shame this question was closed so soon, I think it's slightly different to the linked duplicate. My suggestion would be to use dynamic dispatch, by instantiating the command *before* calling `DispatchCommand`, and passing the command instance to it as a parameter: `IMVCCommand DispatchCommand(TCommand command) where TCommand : IMVCCommand`. This also has the benefit of you being able to supply parameters to the command when you instantiate it – Andrew Williamson Oct 28 '21 at 18:14
  • 2
    @AndrewWilliamson you believe the question is different from duplicate work with OP to editing the question to get it re-opened. (You can start with just editing the question to clarify how duplicate does not solve the problem) – Alexei Levenkov Oct 28 '21 at 18:18
  • @AlexeiLevenkov let me rephrase that - the question is the same, but the *use case*, and thus the suggested answers, are different. I'm not sure I could edit the question to make this more obvious, as you suggest, without providing an answer – Andrew Williamson Oct 28 '21 at 18:27
  • @AndrewWilliamson That you think the OP shouldn't have asked the question that they did doesn't make it not a duplicate. If you think they should so something other than what they've asked how to do, you're more than welcome to post a comment telling them that they should do something else. That wouldn't be an appropriate answer if the question was open though. You're essentially just asking them if they actually have the problem they've specifically stated they have. That's not an answer. – Servy Oct 28 '21 at 18:34

0 Answers0