Resharper's Access to Modified Closure
warnings are usually quite helpful. I was just noticing that when I call the Any
method inside of a for each loop, I'll get a warning if I don't use the open and close parenthesis. As soon as I add ()
, the error goes away.
Does the error itself go away, or have I just accidentally tricked Resharper's static code analysis detection.
<!-- language: lang-vb -->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
Of course, I can fix this by putting the following code inside the For Each
loop and comparing the newPerson.GroupId
to the locally declared variable.
'declare locally to avoid access to modified closure
Dim groupId as Integer = person.groupId