Why doesn't C# infer my generic types?

后端 未结 7 1849
小鲜肉
小鲜肉 2020-11-22 16:38

I\'m having lots of Funcy fun (fun intended) with generic methods. In most cases C# type inference is smart enough to find out what generic arguments it must use on my gener

7条回答
  •  无人共我
    2020-11-22 16:56

    It doesn't use constraints to infer types. Rather it infers types (when possible) and then checks constraints.

    Therefore, while the only possible TResult that could be used with a SomeQuery parameter, it won't see this.

    Note also, that it would be perfectly possible for SomeQuery to also implement IQuery, which is one reason why this is limitation on the compiler may not be a bad idea.

提交回复
热议问题