Public ReadOnly Property DaysOfWeek() As IList(Of DayOfWeek)
Sub New()
Me.DaysOfWeek = New List(Of DayOfWeek)({…some days here…})
End Sub
Public Sub DoThing()
Dim daysOfWeekBitField As Integer = 0
For Each dow As DayOfWeek In Me.DaysOfWeek
daysOfWeekBitField = daysOfWeekBitField Or (1 << CInt(dow))
Next
Dim fail As Boolean = False
For Each con As Container In cons
For Each rt As RateType In rts
For Each rm As RunMode In rms
fail = fail Or Not CheckRate(con, rt, rm) ' This line gets flagged, with vbnet:S2437
Next
Next
Next
So you can see that this is effectively looping over a cross product, and seeing if any return true. Changing to use OrElse would change the behaviour, and may not work as intended.
Specifically quoting the rule description:
Specifically, using AnyValue And -1 will always result in the original value, as will AnyValue Xor 0 and AnyValue Or 0
This doesn’t seem to account for being within a loop, which also appears to be @Hippunky 's case too
@Hippunky : You can work around this issue with this, if there’s no additional logic inside the loop.
Dim daysOfWeekBitField As Integer = Me.DaysOfWeek.Select(Function(X) 1 << X).Sum
@Hippunky and @RowlandShaw : You can workaround this issue by removing the default initialization value from your aggregation variable. CLR will do that for you anyway.
Dim daysOfWeekBitField As Integer 'Remove initialization