9 lines
721 B
Plaintext
9 lines
721 B
Plaintext
=== is related to: S2445
|
|
|
|
=== on 3 Mar 2022, 10:46:00 Antonio Aversa wrote:
|
|
Rule derived from the C# version of S2445, due to this branch of the rule generating a lot of FPs.
|
|
|
|
Valid scenarios using local variables include retrieval of the object being locked from a collection or complex logic, to support a fine graned synchronization, renaming of a readonly field in the context of the current method or locking inside a loop, on the iteration variable.
|
|
|
|
The rule still makes sense, however, for all scenarios which don't require advanced synchronization, and prevents synchronization issues captured by S2445 to be circumvented via a local variable. For example via `var local = new object(); lock (local) { ... }`.
|