C# 访问 base class 的隐式运算符
C# Access to implicit operators of base class
我有以下设置:Entity
派生自 MonoBehaviour
。
MonoBehaviour 实现了到 bool 的隐式转换。现在,如果我在 Entity 中实现到 bool 的隐式转换,它会覆盖 MonoBehaviour 中的转换。
如果我现在想访问旧的和新的转换,我必须转换回基础 class
public class Entity : MonoBehaviour
{
private float CurrentHealthPoints { get; set; }
public static implicit operator bool(Entity entity)
=> (MonoBehaviour)entity && entity.CurrentHealthPoints > 0;
}
现在我的问题是,是否有不同的方法而不必转换为基数 class?我尝试使用 base
关键字,但无法正常工作。
据我所知,除非正在使用的类型利用 contravariance, the explicit casting is inevitable. You can make use of the link to.
我有以下设置:Entity
派生自 MonoBehaviour
。
MonoBehaviour 实现了到 bool 的隐式转换。现在,如果我在 Entity 中实现到 bool 的隐式转换,它会覆盖 MonoBehaviour 中的转换。
如果我现在想访问旧的和新的转换,我必须转换回基础 class
public class Entity : MonoBehaviour
{
private float CurrentHealthPoints { get; set; }
public static implicit operator bool(Entity entity)
=> (MonoBehaviour)entity && entity.CurrentHealthPoints > 0;
}
现在我的问题是,是否有不同的方法而不必转换为基数 class?我尝试使用 base
关键字,但无法正常工作。
据我所知,除非正在使用的类型利用 contravariance, the explicit casting is inevitable. You can make use of the link to.