Skip to content

Commit 3bad1cb

Browse files
Copilotmeziantou
andcommitted
Fix logic bug in Count detection on right side
Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
1 parent e195b78 commit 3bad1cb

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/Meziantou.Analyzer.CodeFixers/Rules/UseAttributeIsDefinedFixer.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ private static async Task<Document> ReplaceWithAttributeIsDefined(Document docum
7575
else
7676
{
7777
// Check for GetCustomAttributes().Count() comparisons
78-
var countInvocation = GetGetCustomAttributesCountInvocation(binaryOperation.LeftOperand, out var countIsOnLeft);
78+
var countInvocation = GetGetCustomAttributesCountInvocation(binaryOperation.LeftOperand, out var foundOnLeft);
79+
var countIsOnLeft = foundOnLeft;
7980
if (countInvocation is null)
8081
{
81-
countInvocation = GetGetCustomAttributesCountInvocation(binaryOperation.RightOperand, out var countIsOnRight);
82-
countIsOnLeft = !countIsOnRight; // If found on right, Count is not on left
82+
countInvocation = GetGetCustomAttributesCountInvocation(binaryOperation.RightOperand, out var foundOnRight);
83+
if (foundOnRight)
84+
{
85+
countIsOnLeft = false; // Count is on right side
86+
}
8387
}
8488

8589
if (countInvocation is not null)

0 commit comments

Comments
 (0)