以下是代码和有问题的行。
当我用鼠标悬停在 src.EnergyServiceLevel 上时,它显示为 null。如果我在上一行中检查 null,那怎么可能呢?
我的猜测是可能有线程导致问题,所以我添加了锁,但并没有帮助。
当我用鼠标悬停在 src.EnergyServiceLevel 上时,它显示为 null。如果我在上一行中检查 null,那怎么可能呢?
我的猜测是可能有线程导致问题,所以我添加了锁,但并没有帮助。
public static ServiceLevelsGroup SafeClone(this ServiceLevelsGroup src) {
ServiceLevelsGroup res = null;
lock (_locker) {
if (src != null) {
res = new ServiceLevelsGroup();
if (src.EnergyServiceLevel != null) {
res.EnergyServiceLevel = new ServiceLevelInfo { ServiceGrade = src.EnergyServiceLevel.ServiceGrade };
if (src.EnergyServiceLevel.Reason != null)
res.EnergyServiceLevel.Reason = src.EnergyServiceLevel.Reason;
}
}
}
return res;
}
在上面的代码中,异常发生在res.EnergyServiceLevel = ...
行。
以下是调试模式下异常发生的截图: