C# Generic Type Inference With Multiple Types

My question is, why can’t TInput be inferred in this situation?

It can – it’s TResult which can’t be inferred, and there’s no way of specifying “partial” inference.

What you can sometimes do is separate the type parameters into ones for a generic type and ones for a generic method, so you’d end up with:

// Explicitly state TResult, and infer TInput
Serializer<MySuperType>.Serialize(x);

Leave a Comment