Skip to content

Commit

Permalink
Use SemanticModel on IInvocationOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
david-acker committed Dec 1, 2023
1 parent b1af754 commit 7c1edb4
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ protected override void InitializeWorker(CompilationStartAnalysisContext context
// but it is recommended to explicitly specify it for clarity and readability:
// https://learn.microsoft.com/dotnet/standard/base-types/best-practices-strings#recommendations-for-string-usage
var methodsWithSameNameAsTargetMethod =
GetAccessibleMethodsWithSameNameAsTargetMethod(
invocationExpression,
targetMethod,
oaContext.Operation.SemanticModel);
GetAccessibleMethodsWithSameNameAsTargetMethod(invocationExpression, targetMethod);

if (methodsWithSameNameAsTargetMethod.HasMoreThan(1))
{
Expand Down Expand Up @@ -216,16 +213,15 @@ private static ParameterInfo GetParameterInfo(INamedTypeSymbol type, bool isArra

private static IEnumerable<IMethodSymbol> GetAccessibleMethodsWithSameNameAsTargetMethod(
IInvocationOperation invocationExpression,
IMethodSymbol targetMethod,
SemanticModel semanticModel)
IMethodSymbol targetMethod)
{
var invocationStart = invocationExpression.Syntax.GetLocation().SourceSpan.Start;

return targetMethod.ContainingType
.GetMembers(targetMethod.Name)
.OfType<IMethodSymbol>()
.Where(method => method.IsStatic == targetMethod.IsStatic &&
semanticModel.IsAccessible(invocationStart, method));
invocationExpression.SemanticModel!.IsAccessible(invocationStart, method));
}
}
}

0 comments on commit 7c1edb4

Please sign in to comment.