Lan*_*nce 0 c# generics inheritance derived-class
我希望在基类(和接口)上定义一个方法,该方法接受派生类作为其参数。
IE
abstract class Base : IBase
{
public void CloneMeToProvidedEntity(??? destination) {};
}
public class Derived : Base
{
public override void CloneMeToProvidedEntity(Derived destination)
{
blah blah ....
}
}
Run Code Online (Sandbox Code Playgroud)
如果有人能告诉我界面是什么样子以及如何做到这一点......或者如果可能的话,我将永远感激不已
满怀期待
槊
您可能正在寻找:
interface IBase<T>
{
void CloneMeToProvidedEntity(T destination);
}
public abstract class Base<T> : IBase<T>
{
public virtual void CloneMeToProvidedEntity(T destination) { }
}
public class Derived : Base<Derived>
{
public override void CloneMeToProvidedEntity(Derived destination)
{
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢@菲尔