使用sonarqube分析我的代碼并被告知“'actor'在至少一個執(zhí)行路徑上為空”以下代碼if (actor.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0)
{actor.ProducerAgreementIds是一個List<string>。這條語句不是已經(jīng)在執(zhí)行空檢查了嗎?或者它應(yīng)該是:if (actor != null && (actor.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0))
{替代方案將只使用條件訪問if (actor?.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0)適當(dāng)且不會引起下游問題?謝謝!
1 回答
慕哥6287543
TA貢獻(xiàn)1831條經(jīng)驗 獲得超10個贊
通過此驗證就足夠了:
if (actor?.ProducerAgreementIds?.Count > 0)
{
}- 1 回答
- 0 關(guān)注
- 90 瀏覽
添加回答
舉報
0/150
提交
取消
