This is a purely aesthetic thing, but I think it is worth asking nonetheless. In the following code:
interface IGiveResult<TResult>
{
TResult GetResult();
}
static class ResultGetter
{
GetResultFrom<TResultGiver, TResult>(TResultGiver giver) where TResultGiver : IGiveResult<TResult>
{
return giver.GetResult();
}
}
To call GetResultFrom
, I need to specify both type parameters like this:
ResultGetter.GetResultFrom<SomeGiverType, SomeResultType>(someGiverInstance);
However, I would like to call is like this:
ResultGetter.GetResultFrom<SomeGiverType>(someGiverInstance);
After all, the compiler has all the information neccessary to infer the second generic type. However, this does not compile. Is it possible to change this code, so that one doesn't have to specify the result type?