Generic Parameter Inference
public static void Do<T>(this TBase value) where T : BaseClass<TBase>
The above line of code does not compile. I've been mulling over this for about half an hour and have not come up with a single logical reason why it shouldn't, strong-typing wise, except that it doesn't.
I can understand why using Type Inference (calling the method without the generic parameter), you could never bind to one predetermined T - after all, there may be an infinite amount of types that derive from BaseClass<TBase> and that's just when using TBase's topmost level of inheritance.
However, using a call to Do with the T generic parameter explicitly stated, there can be only one option for TBase, since:
- It is a class and you can never derive twice from the same type in your line of inheritance, so there's no fearing that T would derive from both BaseClass<A> and BaseClass<B> somewhere along that line.
- It is not an interface, where you could implement both ISomething<A> and ISomething<B>
Does anyone have any ideas?