Cannot inherit from generic base class and specific interface using same type with generic constrain
- by simendsjo
Sorry about the strange title. I really have no idea how to express it any better...
I get an error on the following snippet. I use the class Dummy everywhere. Doesn't the compiler understand the constraint I've added on DummyImplBase? Is this a compiler bug as it works if I use Dummy directly instead of setting it as a constraint?
Error 1 'ConsoleApplication53.DummyImplBase' does not implement interface member 'ConsoleApplication53.IRequired.RequiredMethod()'. 'ConsoleApplication53.RequiredBase.RequiredMethod()' cannot implement 'ConsoleApplication53.IRequired.RequiredMethod()' because it does not have the matching return type of 'ConsoleApplication53.Dummy'. C:\Documents and Settings\simen\My Documents\Visual Studio 2008\Projects\ConsoleApplication53\ConsoleApplication53\Program.cs 37 27 ConsoleApplication53
public class Dummy
{
}
public interface IRequired<T>
{
T RequiredMethod();
}
public interface IDummyRequired : IRequired<Dummy>
{
void OtherMethod();
}
public class RequiredBase<T> : IRequired<T>
{
public T RequiredMethod()
{
return default(T);
}
}
public abstract class DummyImplBase<T> : RequiredBase<T>, IDummyRequired
where T: Dummy
{
public void OtherMethod()
{
}
}