我正在尝试在C#中执行以下操作:
public abstract class X
{
Y<this> y { get; set; }
}
基本上是“ this”指向X的当前子类的类型。我该怎么办?
X
也必须是通用的-这是常见模式。public abstract class X<T>
where T : X<T>
// ...
public class Y : X<Y>
// ...
您应该能够在运行时进行转换,并使用.GetType()
对实例进行检查,以帮助做出明智的决定。