【发布时间】:2019-09-20 05:14:40
【问题描述】:
我正在使用 sonarqube 分析我的代码并遇到以下方法的错误
public static AllocationRuleList AsAllocationRuleList(this SIGACORD.Policy acordPolicy)
{
foreach (var OlifeExt in acordPolicy.OLifEExtension)
{
var elements = new List<XmlElement>();
foreach (var ele in OlifeExt.Any)
{
if (ele.Name == "AllocationRestrictions")
{
var allocationRestrictionElement = acordPolicy.OLifEExtension[0]["AllocationRestrictions"];
return allocationRestrictionElement.AsAllocationRuleList();
}
}
break;
}
return null;
}
sonarqube 说我的break 应该被删除或设置为有条件的。但是,这在逻辑上不正确吗?
【问题讨论】:
-
您开始迭代一个集合,并在第一个循环之后中断。这很奇怪,它指出它很奇怪。
-
它只允许您运行第一次迭代,例如,您可以使用 System.Linq 命名空间中的
var OlifeExt = acordPolicy.OLifEExtension.First()。