【发布时间】:2020-04-12 05:57:17
【问题描述】:
我有以下设置:Entity 派生自 MonoBehaviour。
MonoBehaviour 实现了到 bool 的隐式转换。现在,如果我在 Entity 中实现到 bool 的隐式转换,它会覆盖 MonoBehaviour 中的转换。
如果我现在想同时访问旧转换和新转换,我必须强制转换回基类
public class Entity : MonoBehaviour
{
private float CurrentHealthPoints { get; set; }
public static implicit operator bool(Entity entity)
=> (MonoBehaviour)entity && entity.CurrentHealthPoints > 0;
}
现在我的问题是,有没有一种不同的方法而不必强制转换为基类?我尝试使用 base 关键字,但无法使用。
【问题讨论】:
标签: c# oop implicit-conversion