鉴于这些 C# 类(由 WCF 生成,我无法更改这些):
public SysState GetSysState();
public class SysState { /* nothing much here */}
public class Normal : SysState { /* properties & methods */ }
public class Foobar : SysState { /* different properties & methods */ }
我的代码(当前):
SysState result = GetSysState();
if (result is Normal) HandleNormal((Normal) result);
if (result is Foobar) HandleFoobar((Foobar) result);
我的问题:我一直觉得我遗漏了一些明显的东西,我不需要明确检查类型。我有高级的时刻吗?