Resharper 的Access to Modified Closure
警告通常很有帮助。我只是注意到,当我在Any
for each 循环中调用该方法时,如果我不使用左括号和右括号,我会收到警告。一旦我添加()
,错误就会消失。
错误本身是否消失了,或者我只是不小心欺骗了 Resharper 的静态代码分析检测。
Dim groupExists as Boolean
For each oldPerson in oldData
'access to modified closure warning on oldPerson.groupId
groupExists = (From newPerson In newData
Where newPerson.GroupId = oldPerson.groupId).Any
'no closure problem reported
groupExists = (From newPerson In newData
Where newPerson.GroupId = oldPerson.groupId).Any()
Next
当然,我可以通过将以下代码放入For Each
循环中并将 与newPerson.GroupId
本地声明的变量进行比较来解决此问题。
'declare locally to avoid access to modified closure
Dim groupId as Integer = person.groupId