-
Notifications
You must be signed in to change notification settings - Fork 14
Improve internal analyzer regarding AppImplementationFactory
#1234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
foreach (var attribute in attributes) | ||
{ | ||
if (attribute.AttributeClass?.Name == MarkerAttributeName) | ||
return true; | ||
} |
Check notice
Code scanning / CodeQL
Missed opportunity to use Where Note
implicitly filters its target sequence
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 25 days ago
To fix the problem, we should replace the foreach
loop that filters elements with a foreach
loop that iterates over a filtered collection using the Where
method. This change will make the code more readable and expressive by clearly indicating the filtering intent.
- Modify the
IsMarkedWithAttribute
method to use theWhere
method for filtering theattributes
collection. - Specifically, change the
foreach
loop on line 381 to iterate overattributes.Where(attribute => attribute.AttributeClass?.Name == MarkerAttributeName)
.
-
Copy modified line R381 -
Copy modified line R383
@@ -380,6 +380,5 @@ | ||
var attributes = symbol.GetAttributes(); | ||
foreach (var attribute in attributes) | ||
foreach (var attribute in attributes.Where(attribute => attribute.AttributeClass?.Name == MarkerAttributeName)) | ||
{ | ||
if (attribute.AttributeClass?.Name == MarkerAttributeName) | ||
return true; | ||
return true; | ||
} |
foreach (var typeArgumentListSyntax in typeArgumentLists) | ||
{ | ||
if (typeArgumentListSyntax.Parent is not NameSyntax methodName) | ||
continue; | ||
if (context.SemanticModel.GetSymbolInfo(methodName).Symbol is not IMethodSymbol method) | ||
continue; | ||
if (!factoryMethods.Contains(method.OriginalDefinition, _comparer)) | ||
continue; | ||
|
||
typeArgumentList = typeArgumentListSyntax; | ||
break; | ||
} |
Check notice
Code scanning / CodeQL
Missed opportunity to use Where Note
implicitly filters its target sequence
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 25 days ago
To fix the problem, we should replace the foreach
loop that filters elements using a continue
statement with a foreach
loop that iterates over a filtered sequence using the Where
method from LINQ. This change will make the code more readable and maintainable by clearly expressing the filtering logic.
- Modify the
foreach
loop on line 415 to use theWhere
method to filtertypeArgumentLists
before iterating over it. - Ensure that the filtering condition
typeArgumentListSyntax.Parent is not NameSyntax methodName
is moved into theWhere
method.
-
Copy modified line R415 -
Copy modified line R417
@@ -414,6 +414,5 @@ | ||
.ToArray(); | ||
foreach (var typeArgumentListSyntax in typeArgumentLists) | ||
foreach (var typeArgumentListSyntax in typeArgumentLists.Where(t => t.Parent is NameSyntax)) | ||
{ | ||
if (typeArgumentListSyntax.Parent is not NameSyntax methodName) | ||
continue; | ||
var methodName = (NameSyntax)typeArgumentListSyntax.Parent; | ||
if (context.SemanticModel.GetSymbolInfo(methodName).Symbol is not IMethodSymbol method) |
|
Description
AppImplementationFactory
in constructor/field initializerAppImplementationFactory
that is not marked withImplementableByAppsAttribute
Did a bunch of manual testing, will add my manual test code as automated tests after #651
Related Issue(s)
ServiceLifetime
#757Verification
Documentation