No, your analysis and solution look right. In fact, type type inference can only work on an all-or-nothing basis. If there are any general parameters that cannot be displayed, all of them must be explicitly specified. Personally, I would really like to say "you are worried about these parameters, I will tell you this," but ... this does not exist.
The only other option is to add an artificial extra regular parameter so that it can output the general parameter - a little yucky.
Another option: challenge the suggestion that generics are needed. For example, could it be an instance of Type
? Will be:
bool Handle<TModel>(TModel model, Type type)... ... Handle(model, typeof(MyCommandHandler));
work for example? I cannot answer this directly since I donβt know the details of your _container.Resolve<TCommandHandler>();
as to whether it can be adjusted to take Type
and not <T>
.
source share