Skip to content

Commit

Permalink
fix member access for enum and such scanned incorrectly by the ref pa…
Browse files Browse the repository at this point in the history
…rameter analyzer because of parameter symbol ToString code smell
  • Loading branch information
xiaoxiao921 committed Jan 24, 2022
1 parent 1490127 commit baa8208
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ private static void CheckExpressionSyntaxes(SyntaxNodeAnalysisContext context, M
foreach (var parameter in method.ParameterList.Parameters)
{
// If parameter is a reference type and is not a literal assignment no warning needed
if (context.SemanticModel.GetDeclaredSymbol(parameter, context.CancellationToken).Type.IsReferenceType)
var parameterSymbol = context.SemanticModel.GetDeclaredSymbol(parameter, context.CancellationToken);
if (parameterSymbol.Type.IsReferenceType)
{
if (!(expressionSyntaxes[i] is AssignmentExpressionSyntax assignment))
{
continue;
}
}

// TODO : Looking through the ToString() and "ref" is not the cleanest
var parameterSplit = parameter.ToString().Split(' ');
if (parameterSplit.Any(s => s == varNames[i]) && !parameterSplit.Any(s => s == "ref" || s == "out"))
var paramaterName = parameterSymbol.Name;
if (parameterSymbol.RefKind == RefKind.None && paramaterName == varNames[i])
{
context.ReportDiagnostic(Diagnostic.Create(Rule, expressionSyntaxes[i].GetLocation(), expressionSyntaxes[i].ToString()));
}
Expand Down

0 comments on commit baa8208

Please sign in to comment.