Implementing this interface is straight forward:
public class MyInterfaceImpl : IMyInterface
{
public List<IMyInterface> GetAll(string whatever)
{
return new List<IMyInterface> { new MyInterfaceImpl(), this };
}
}
Please note that the method signature needs to be exactly the same, i.e. the return type has to be List<IMyInterface>
and not List<MyInterfaceImpl>
.
If you want the type in the list to be the same type as the class that implements the interface, you will have to use generics:
public interface IMyInterface<T> where T : IMyInterface<T>
{
List<T> GetAll(string whatever)
}
public class MyInterfaceImpl : IMyInterface<MyInterfaceImpl>
{
public List<MyInterfaceImpl> GetAll(string whatever)
{
return new List<MyInterfaceImpl > { new MyInterfaceImpl(), this };
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…