I have a piece of code that currently looks like this:
Signature of the Subscribe method:
void Subscribe<T, TResult>(Func<T, TResult> action);
class Service {
int methodThatRequiresIntAndReturnsInt(int i) => i * 2;
}
In my mind it should be possible to extrapolate what the types for T and TReturn when trying to use the subscribe method, however compiler tells me that the types cannot be inferred from usage, meaning i end up writing this code:
Queue.Subscribe<int, int>(Service.methodThatRequiresIntAndReturnsInt);
My question is whether it is possible and if so how should the method signature/usage look so that it would be possible to use it without type hinting e.g.:
Queue.Subscribe(input => input * 2);
Current implementation is along the lines of this:
_commandSubscription.Subscribe<CreateUpdateCommand, bool>(Resolve<UpdateService>().CreateUpdate);
_commandSubscription.Subscribe<AddCommentCommand>(Resolve<UpdateService>().AddComment);
The implementations for the service methods are as follows:
public class UpdateService {
public void AddComment(AddCommentCommand command) {
// DO STUFF
}
public bool CreateUpdate(CreateUpdateCommand command) {
// Do stuff
return true;
}
}