jeudi 28 octobre 2021

C# How to make more clear Generic Methods

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...





Aucun commentaire:

Enregistrer un commentaire