Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9089b70
commit 22b02cc
Showing
4 changed files
with
76 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...er.UnitTest/TestCases/LockedFieldShouldBePrivateAndReadonly.CSharp9.TopLevelStatements.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
lock ("a string") { } // Noncompliant | ||
// ^^^^^^^^^^ | ||
lock (MethodReturningString()) { } // Noncompliant | ||
lock (new object()) { } // Noncompliant | ||
|
||
string MethodReturningString() => "a string"; | ||
|
||
class ClassNestedAtTopLevel | ||
{ | ||
readonly object readonlyField = new(); | ||
object readWriteField = new(); | ||
|
||
static readonly object staticReadonlyField = new(); | ||
static object staticReadWriteField = new(); | ||
|
||
void Test() | ||
{ | ||
lock (readonlyField) { } | ||
lock (readWriteField) { } // Noncompliant | ||
lock (staticReadonlyField) { } | ||
lock (staticReadWriteField) { } // Noncompliant | ||
} | ||
|
||
class SecondLevelNesting | ||
{ | ||
readonly object readonlyField = new(); | ||
object readWriteField = new(); | ||
|
||
static readonly object staticReadonlyField = new(); | ||
static object staticReadWriteField = new(); | ||
|
||
void Test() | ||
{ | ||
lock (readonlyField) { } | ||
lock (readWriteField) { } // Noncompliant | ||
lock (staticReadonlyField) { } | ||
lock (staticReadWriteField) { } // Noncompliant | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters