有没有办法为接口指定允许的子类?
假设我有这些课程:
public interface IDoable // specify that only A or it's subclasses can implement IDoable
{
void Do();
}
public class A : IDoable
{
public void Do(){};
public void Foo(){};
}
public class B : IDoable // implementing IDoable on something other than A or its sublcasses doesn't make any sense
{
// public void Do();
}
所以以后我将能够做到这一点:
IDoable d = new A();
d.Do();
d.Foo(); // I'd like to be able to do this.
C# 支持这种特性吗?