Given the following classes...
public abstract class FooBase<TBar> where TBar : BarBase{}
public abstract class BarBase{}
public class Bar1 : BarBase{}
public class Foo1 : FooBase<Bar1> {}
...and the following method...
public TBar DoSomething<TFoo, TBar>(TFoo theFoo)
where TFoo : FooBase<TBar>
where TBar : BarBase
{
return default(TBar);
}
Why can't the following line of code imply the return type?
Bar1 myBar = DoSomething(new Foo1());
Instead I have to specify the generic types like this...
Bar1 myBar = DoSomething<Foo1, Bar1>(new Foo1());
FooBase<TBar>
, here we are saying after you know what typeTBar
is, thenFooBase<TBar>
will becomeFeeBase<ActualType>
. This constraint can't be used as part of type inference, because we don't know the type until inference completes. It'd be circular logic. – Malcolmmalcom