I've written a blog post on this very issue.
So basically what I've done in the past is to create an abstract base class for your Command Processor along with a generic one:
public abstract class CommandProcessor
{
public abstract Error ProcessCommand(Command command);
}
public abstract class CommandProcessor<TCommand> where TCommand : Command
{
public override Error ProcessCommand(Command command)
{
if (command is TCommand == false)
throw new ArgumentException("command should be of type TCommand");
var cast = (TCommand)command;
return this.ProcessCommand(cast);
}
public abstract Error ProcessCommand(TCommand command);
}
Now you don't need to do anything special dependant of what type of Command you are using:
protected virtual CommandProcessingResult RecogniseAndProccessCommand<T>
(T command) where T : Command
{
var commandProcessor = (CommandProcessor)ServiceLocator.GetInstance<ICommandProcessorGeneric>(typeof(T).Name);
return commandProcessor.ProcessCommand(command);
}